encodeBigIntBe function

Uint8List encodeBigIntBe(
  1. BigInt input, {
  2. int length = 0,
})

Implementation

Uint8List encodeBigIntBe(BigInt input, {int length = 0}) {
  int byteLength = (input.bitLength + 7) >> 3;
  int reqLength = length > 0 ? length : max(1, byteLength);
  assert(byteLength <= reqLength, 'byte array longer than desired length');
  assert(reqLength > 0, 'Requested array length <= 0');

  var res = Uint8List(reqLength);
  res.fillRange(0, reqLength - byteLength, 0);

  var q = input;
  for (int i = 0; i < byteLength; i++) {
    res[reqLength - i - 1] = (q & _byteMask).toInt();
    q = q >> 8;
  }
  return res;
}