PHP按位XOR与JavaScript按位XOR

时间:2018-07-15 01:09:01

标签: javascript php binary bitwise-operators xor

我正在尝试寻找一种方法来使PHP Bitwise XOR的结果与JavaScript Bitwise XOR的结果相匹配。我遇到了这个问题的不同问题,而所有问题都没有答案。以下是其中一些:

Javascript & PHP Xor equivalent

php bitwise XOR and js bitwise XOR producing different results

JS bitwise XOR operator acts differently from PHP’s counterpart. How to get the same result as PHP returns?

我知道PHP与32位JavaScript相比使用的是64位,但是我的问题是,是否有任何手动方法来计算相似结果?我们如何使PHP获得与JS类似的结果?

如果数字短,则结果在JS和PHP中将始终相同,但是,如果数字长,则发生此问题。示例:

var a = 234324234232;
var b = 221312312232;
console.log(a^b);

JS输出:

166587472

PHP代码:

$a = 234324234232;
$b = 221312312232;
echo $a^$b;

PHP输出:

21641423952

有时JavaScript会给出负面结果:

var a = 202338273;
var b = 523511134400;
console.log(a^b);

JS输出

-272722143

PHP代码:

$a = 202338273;
$b = 523511134400;
echo $a^$b;

PHP输出:

523713287969

1 个答案:

答案 0 :(得分:1)

屏蔽为已签名的整数。

>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:859] OS X does not support NUMA - returning NUMA node zero
tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7335
pciBusID: 0000:46:00.0
totalMemory: 8.00GiB freeMemory: 2.32GiB
tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
tensorflow/core/common_runtime/gpu/gpu_device.cc:929]      0 
tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0:   N 
tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/device:GPU:0 with 2025 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080, pci bus id: 0000:46:00.0, compute capability: 6.1)
True