Javascript bitwise difference

To check, I wrote a simple function:

function test() {
   var val = -1878897367 & 0xfffffff0; 
   console.log(val);
   val = -2146277048 & 0xfffffff0; 
   console.log(val);
}

Result of working on a desktop computer:

-1878897376
-2146277056

The result of work on phones (Phonegap on Android 4.2 or 2.3.4):

268586281
1206600

Why is this happening?

+3
source share
2 answers

I believe the reason for this is a different bit operating system. Bitwise operators work with 32-bit integers. Bitwise operations are performed differently based on the bits used in the operating system.

0
source

Of course, this is a mistake:

toInt32(-1878897367) & toInt32(0xfffffff0) =
-1878897367 & -16 =
10010000000000100100110100101001 & 11111111111111111111111111110000 =
10010000000000100100110100100000 =
-1878897376

http://www.ecma-international.org/ecma-262/5.1/#sec-11.10

0
source

All Articles