bitsToBigIntWithLengthLimit static method

BigInt bitsToBigIntWithLengthLimit(
  1. List<int> data,
  2. int qlen
)

Converts a sequence of bits represented as a byte array to a BigInt integer.

This method takes a byte array 'data' containing a sequence of bits and converts it into a BigInt integer 'x' by interpreting the binary data as a hexadecimal string. The result 'x' is then right-shifted, if necessary, to ensure it doesn't exceed 'qlen' bits in length.

Parameters:

  • data: A List
  • qlen: The maximum bit length for the resulting integer.

Returns:

  • BigInt: A BigInt integer representing the converted bits with 'qlen' bits.

Details:

  • The method first converts the binary data to a hexadecimal string, which is then parsed into a BigInt.
  • If the length of 'x' exceeds 'qlen', it's right-shifted to reduce it to the specified length. Otherwise, 'x' remains unchanged.

Note: The method assumes that 'data' is big-endian (most significant bits first). Any padding bits will be removed as needed to match 'qlen'.

Implementation

static BigInt bitsToBigIntWithLengthLimit(List<int> data, int qlen) {
  BigInt x = BigInt.parse(BytesUtils.toHexString(data), radix: 16);
  int l = data.length * 8;

  if (l > qlen) {
    return (x >> (l - qlen));
  }
  return x;
}