32 位上的 gmp_xor 问题
在 64 位机器上
(1 ^ 2489596804)
给出 -1805370491
作为响应。但是,当我在 32 位 PHP 机器上执行此操作时,我得到 2489596805
响应。
因此,我尝试使用 gmp_strval(gmp_xor(1,2489596804))
在 32 位计算机上运行它,但它也会产生 2489596805
。那么到底是怎么回事,我怎样才能得到正确的回应呢?
更新:我刚刚注意到 64 位结果是从中减去 32 位最大值所得的结果 (4294967295
)。
On a 64-bit machine
(1 ^ 2489596804)
gives -1805370491
in response. However, when I do this on a 32-bit PHP machine, I get 2489596805
in response.
So, I tried to get it working on the 32-bit machine using gmp_strval(gmp_xor(1,2489596804))
, but it also yields 2489596805
. So what's up, and how can I get the right response?
Update: I just noticed that the 64-bit result is what you get from subtracting the 32-bit max from it (4294967295
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是相同的结果,只是解释不同:
您在 64 位计算机上看到负值的原因是您将该结果解释为带符号的 32 位整数。
如果你真的想在两种解释之间进行转换,我想你必须自己做。一个简单的方法是这样的:
It's the same result, simply interpreted differently:
The reason you see a negative value on your 64-bit machine is that you're interpreting that result as a signed 32-bit integer.
If you really want to convert between the two interpretations, I think you'll have to do this yourself. A simple way to do that would be something like this: