I have a very large number represented as binary in JavaScript:
var largeNumber = '11010011010110100001010011111010010111011111000010010111000111110011111011111000001100000110000011000001100111010100111010101110100010001011010101110011110000011000001100000110000011001001100000110000011000001100000110000111000011100000110000011000001100000110000011000010101100011001110101101001100110100100000110000011000001100000110001001101011110110010001011010001101011010100011001001110001110010100111011011111010000110001110010101010001111010010000101100001000001100001011000011011111000011110001110111110011111111000100011110110101000101100000110000011000001100000110000011010011101010110101101001111101001010010111101011000011101100110010011001001111101'
When I convert it to decimal by use of parseInt(largeNumber, 10)
l it gives me 1.5798770299367407e+199
but when I try to convert it back to binary:
parseInt(`1.5798770299367407e+199`, 2)
it returns 1
(which I think is related to how parseInt
works by rounding value) when I was expecting to see my original binary representation of largeNumber
. Can you explain me such behavior? And how I can convert it back to original state in JavaScript?
EDIT: This question is a result of my experiment where I was playing around with storing and transferring large amount of boolean data. The largeNumber
is a representation of a collection [true,true,false,true ...]
of boolean values which has to be shared between client, client worker and server.
parseInt
isn't a method of converting from one number system to another. You need to go read what it actually does, then rethink how you achieve your end result.largeNumber
?