number method
Gets an unsigned integer of bitLength-bit from the message digest.
If endian is Endian.little, it will treat the digest bytes as a little
endian number; Otherwise, if endian is Endian.big, it will treat the
digest bytes as a big endian number.
On the web, an int is a 64-bit floating point number, so results above
2^53 cannot be represented exactly. Keep bitLength at 53 or below for
exact values on that platform.
Implementation
int number([int bitLength = 64, Endian endian = Endian.big]) {
if (bitLength < 8 || bitLength > 64 || (bitLength & 7) > 0) {
throw ArgumentError(
'Invalid bit length. '
'It must be a number between 8 to 64 and a multiple of 8.',
);
} else {
bitLength >>>= 3;
}
// Accumulate with `* 256 +` rather than `<< 8 |` to support the web
int result = 0;
int n = bytes.length;
if (endian == Endian.little) {
for (int i = (n > bitLength ? bitLength : n) - 1; i >= 0; i--) {
result = result * 256 + bytes[i];
}
} else {
for (int i = n > bitLength ? n - bitLength : 0; i < n; i++) {
result = result * 256 + bytes[i];
}
}
return result;
}