According to the documentation, one can convert a binary representation of a number to the number itself using parseInt(string, base).
For instance,
var number = parseInt("10100", 2);
// number is 20
However, take a look at the next example:
var number = parseInt("1000110011000011101000010100000110011110010111111100011010000", 2);
// number is 1267891011121314000
var number = parseInt("1000110011000011101000010100000110011110010111111100100000000", 2);
// number is 1267891011121314000
How is this possible?
Note that the binary numbers are almost the same, except for the last 9 bits.
1267891011121314000 is way over Number.MAX_SAFE_INTEGER (9007199254740991). It can't safely represent it in memory.
Take a look at this classic example:
1267891011121314000 == 1267891011121314001 // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With