getByteArray function

Uint8List getByteArray(
  1. BigInt integer
)

Implementation

Uint8List getByteArray(BigInt integer) {
  // Big-endian representation
  final bitLength = integer.bitLength;
  final byteLength = (bitLength + 7) ~/ 8;
  final result = Uint8List(byteLength);
  var v = integer;
  for (var i = byteLength - 1; i >= 0; i--) {
    result[i] = (v & BigInt.from(0xFF)).toInt();
    v >>= 8;
  }
  return result;
}