writeBigInt static method
Implementation
static Uint8List writeBigInt(BigInt number) {
// Not handling negative numbers. Decide how you want to do that.
int bytes = (number.bitLength + 7) >> 3;
var b256 = BigInt.from(256);
var result = Uint8List(bytes);
if (Endian.host == Endian.big) {
for (int i = 0; i < bytes; i++) {
result[i] = number.remainder(b256).toInt();
number = number >> 8;
}
} else {
for (int i = 0; i < bytes; i++) {
result[bytes - 1 - i] = number.remainder(b256).toInt();
number = number >> 8;
}
}
return result;
}