toBytes method

Uint8List toBytes()

Implementation

Uint8List toBytes() {
  if (this == BigInt.zero) return Uint8List.fromList([0]);

  var hex = toRadixString(16);
  if (hex.length % 2 != 0) hex = '0' + hex;

  var bytes = <int>[];
  for (var i = 0; i < hex.length; i += 2) {
    bytes.add(int.parse(hex.substring(i, i + 2), radix: 16));
  }
  return Uint8List.fromList(bytes);
}