How can I make the PHP version of Bitwise XOR match the javascript version?

0

How can I make the PHP version of Bitwise XOR match the javascript version?

The javascript version gives me 1080

(f6o5y5^t0u1)+(p6t0k1^l2v2)+(j0u1f6^d4d4)+(p6t0k1^l2v2)

While the PHP gives me 0000

$a = f6o5y5^t0u1 & 0xffffffff;
if ($a & 0x80000000)
  $a -= 0x100000000;

$b = p6t0k1^l2v2 & 0xffffffff;
if ($b & 0x80000000)
  $b -= 0x100000000;

$c = j0u1f6^d4d4 & 0xffffffff;
if ($c & 0x80000000)
  $c -= 0x100000000;

$d = p6t0k1^l2v2 & 0xffffffff;
if ($d & 0x80000000)
  $d -= 0x100000000;

echo $a.$b.$c.$d;   
javascript
php
bit-manipulation
xor
bitwise-xor
asked on Stack Overflow Mar 23, 2019 by William Cross

1 Answer

0

The syntax is the same, the implementation in your sample is different. For example, the following Javascript:

var x = (1^2)+(3^4)+(5^6)+(4^8);
console.log(x);

Will output x as 25;

The PHP version is the same. For example:

<?=(1^2)+(3^4)+(5^6)+(4^8)?>

Will also render 25.

My guess is you do not have the same values or your syntax is the different in the different languages.

answered on Stack Overflow Mar 23, 2019 by Tigger

User contributions licensed under CC BY-SA 3.0