writeIntLE function

Uint8List writeIntLE(
  1. dynamic value,
  2. int byteLength
)

Implementation

Uint8List writeIntLE(dynamic value, int byteLength) {
  final bn = bnToBn(value);

  final List<int> pipe = [];
  int i = 0;
  BigInt mul = BigInt.from(256);
  BigInt sub = BigInt.zero;
  int byte = (bn % mul).toInt();
  pipe.add(byte);
  while (++i < byteLength) {
    if (bn < BigInt.zero && sub == BigInt.zero && byte != 0) {
      sub = BigInt.one;
    }
    byte = ((bn ~/ mul - sub) % BigInt.from(256)).toInt();
    pipe.add(byte);
    mul *= BigInt.from(256);
  }

  return Uint8List.fromList(pipe);
}