문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top