javascript - Performing bitwise operations on large values -
I want to take a bitwise action with some larger values:
var someVariable = 4 ; Some variables | = 36028797018963968; // Add flag, 1 & lt; & Lt; 55
However, the result is always going to be 36028797018963972
rather than 4
. After some research, I came to know that Javascript turns the number to 32-bit representation when bitwise is operating, which tells me why this problem is happening, but how can I fix this? After some more research, I found some javascript in Binton libraries, but I would like to do without libraries if possible, how can I do a large number of bitwind operations in Javascript?
variable number MAX_SAFE_INTEGER
in Chrome can be used for maximum math Keeps the safest number.
This number is return number in my ChromeMXCAIFIITER = 9007199254740991. Your number is big.
Try this exam:
var a = 36028797018963968; Var B = A + 1; Console.log (a == b); // print true console.log (a === b); // right print / code> var a = number MAX_SAFE_INTEGER; A.toString (2); // print "11111111111111111111111111111111111111111111111111111" (a + 1) .to string (2); // print "1000000000000000000000000000000000000000000000000000000000" & lt; - 2 ^ 56 (A + 2) .to string (2); // print "10000000000000000000000000000000000000000">
Comments
Post a Comment