encodeBigInt function

Uint8List encodeBigInt(
  1. BigInt number, {
  2. Endian endian = Endian.little,
  3. int? bitLength,
})

Implementation

Uint8List encodeBigInt(BigInt number,
    {Endian endian = Endian.little, int? bitLength}) {
  var bl = (bitLength != null) ? bitLength : number.bitLength;
  int size = (bl + 7) >> 3;
  var result = Uint8List(size);

  for (int i = 0; i < size; i++) {
    result[endian == Endian.little ? i : size - i - 1] =
        (number & BigInt.from(0xff)).toInt();
    number = number >> 8;
  }
  return result;
}