toUin8List method

Uint8List toUin8List()

Converts this BigInt into a Uint8List encoding it with the big-endian encoding.

Implementation

Uint8List toUin8List() {
  // Not handling negative numbers. Decide how you want to do that.
  final byteMask = BigInt.from(0xff);
  var number = this;
  final size = (number.bitLength + 7) >> 3;
  final result = Uint8List(size);

  for (var i = 0; i < size; i++) {
    result[size - i - 1] = (number & byteMask).toInt();
    number = number >> 8;
  }
  return result;
}