bigIntToBytes static method

List<int> bigIntToBytes(
  1. BigInt b,
  2. int numBytes
)

Implementation

static List<int> bigIntToBytes(BigInt b, int numBytes) {
  var bytes = List<int>.filled(numBytes, 0, growable: true);
  for (var i = 0; i < numBytes; i++) {
    bytes[i] = 0;
  }
  var biBytes = encodeBigInt(b);
  var start = (biBytes.length == numBytes + 1) ? 1 : 0;
  var length = min(biBytes.length, numBytes);
  BytesUtils.arraycopy(biBytes, start, bytes, numBytes - length, length);
  return bytes;
}