binaryToDecimal function

String binaryToDecimal(
  1. Uint8List bignum, {
  2. dynamic minDigits = 1,
})

Convert bignum to an unsigned decimal number @param minDigits 0-pad result to this many digits

Implementation

String binaryToDecimal(Uint8List bignum, {minDigits = 1}) {
  var result = List.filled(minDigits, '0'.codeUnitAt(0), growable: true);
  for (var i = bignum.length - 1; i >= 0; --i) {
    var carry = bignum[i];
    for (var j = 0; j < result.length; ++j) {
      var x = ((result[j] - '0'.codeUnitAt(0)) << 8) + carry;
      result[j] = '0'.codeUnitAt(0) + x % 10;
      carry = (x ~/ 10) | 0;
    }
    while (carry != 0) {
      result.add('0'.codeUnitAt(0) + carry % 10);
      carry = (carry ~/ 10) | 0;
    }
  }
  return String.fromCharCodes(result.reversed.toList());
}