I have worked the same process in JavaScript and C# with the & operator, but the result was different.
C# Code
Int64 x = (634586400000000000 & 4611686018427387903);
x= 634586400000000000;
JavaScript Code
var x = (634586400000000000 & 4611686018427387903);
x= 0;
Any ideas?
Bitwise operators in javascript convert the operands to signed 32-bit integers (from the native IEEE 754 floats numbers are stored in).
It looks to me like you're exceeding JavaScript's maximum integer value. The maximum supported value for JavaScript integers is spec'd at 2^53.
UPDATE:
My initial response here wasn't correct - the issue is not JavaScript's max integer value, it's the max value of each operand handled by the ampersand op:
var biggest = 4294967291; // maximum 32 bit unsigned integer
alert(biggest & 1); // alerts 1
alert((biggest + 1) & 1); // alerts 0
Happy coding!
B
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