php按位XOR和js按位XOR产生不同的结果 [英] php bitwise XOR and js bitwise XOR producing different results

查看:113
本文介绍了php按位XOR和js按位XOR产生不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在php和js中执行按位XOR运算时,它们会在某些情况下产生不同的结果,例如

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)

我的理解是因为php运行64位而不是32位js。

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是32位计算中整数的最大正值,(它是2 ^ 16,32的一半)我们有一些比特,另一半是为负数保留的。)

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.)

一旦你使用的数字大于32位系统中的数字,你就会开始像计算机那样获得棘手的结果认为这是一个负数。请参阅 https://en.wikipedia.org/wiki/Integer_(computer_science)

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)

这篇关于php按位XOR和js按位XOR产生不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆