Why does it return value when using & operator in JavaScript and C #?

I worked with the same process in JavaScript and C # with the and operator, but the result was different.

C # code

Int64 x = (634586400000000000 & 4611686018427387903);
x= 634586400000000000;

JavaScript code

var x = (634586400000000000 & 4611686018427387903);
x= 0;

Any ideas?

+5
source share
3 answers

Bitwise operators in javascript convert operands to signed 32-bit integers (from IEEE 754 built-in floating-point numbers are stored).

+5
source

It seems to me that you have exceeded the maximum integer value of JavaScript. The maximum supported value for JavaScript integers is specified in 2 ^ 53.

UPDATE:

- JavaScript max, , op:

var biggest = 4294967291; // maximum 32 bit unsigned integer
alert(biggest & 1); // alerts 1
alert((biggest + 1) & 1); // alerts 0

!

B

+2

Bitwise operators deal with a maximum of 32 bits. I don’t know how behavior is defined when you ask it to deal with larger values.

0
source

All Articles