Hexadecimal XOR with 2 values in PHP and JavaScript
I can't find the solution for very easy qu开发者_运维技巧estion.
Code in JavaScript:
var x = -1 ^ 0xF00F9344;
In this case x value is 267414715
Code in PHP:
$x = -1 ^ 0xF00F9344;
The result is -4027552581
Any idea, how to get 267414715 (correct) result in PHP?
While javascript bit operations are always 32-bit, php depends on the platform's word size:
on a 32-bit platform
$n = "11110000000011111001001101000100"
-1^$n = "00001111111100000110110010111011" = 267414715
on a 64 bit platform
$n = "0000000000000000000000000000000011110000000011111001001101000100"
-1^$n = "1111111111111111111111111111111100001111111100000110110010111011" = -4027552581
精彩评论