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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.