Domanda

To test, I wrote a simple function:

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

The result of running on a desktop computer:

-1878897376
-2146277056

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

268586281
1206600

Why is this happening?

È stato utile?

Soluzione

I believe the reason behind this is the different kinds of bits operating system. Bitwise operators work on 32 bit integers. Bitwise operations results differently based on the bits used in the operating system.

Altri suggerimenti

Surely that is a bug:

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top