简体   繁体   中英

php bitwise XOR and js bitwise XOR producing different results

When I try to perform bitwise XOR operation in php and js, they are producing different results in some cases , for example

2166136261 ^ 101 = -2128831072 on browsers (js)
2166136261 ^ 101  = 2166136224(php)

My understanding is because php is running 64 bit as opposed to 32 bit js.

Can anyone tell me the exact reason and if this could be solved so that both operations result in same value. Thanks!

2,147,483,647 is the biggest possible positive value for an integer in 32 bit computing, (it's 2^16, half of the 32 bits we have, the other half are reserved for negative numbers.)

Once you use a number bigger than that in a 32 bit system you start getting screwy results as the computer thinks it's a negative number. see https://en.wikipedia.org/wiki/Integer_(computer_science)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM