encode method

Uint8List encode(
  1. BigInt number
)

Encode a BigInt into bytes using big-endian encoding.

Implementation

Uint8List encode(BigInt number) {
  final _byteMask = BigInt.from(0xff);
  // Not handling negative numbers. Decide how you want to do that.
  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;
}