freezer/lib/utils.dart

31 lines
661 B
Dart

import 'dart:typed_data';
class Utils {
static List<int> splitDigits(int number) {
final digits = <int>[];
while (number != 0) {
digits.add(number % 10);
number = number ~/ 10;
}
return digits;
}
static Uint8List serializeBigInt(BigInt bi) {
Uint8List array = Uint8List((bi.bitLength / 8).ceil());
for (int i = 0; i < array.length; i++) {
array[i] = (bi >> (i * 8)).toUnsigned(8).toInt();
}
return array;
}
static BigInt deserializeBigInt(Uint8List array) {
var bi = BigInt.zero;
for (var byte in array.reversed) {
bi <<= 8;
bi |= BigInt.from(byte);
}
return bi;
}
}