主要因为 PHP 运行在 64位, js 是 32位,造成的.
问题表现:
In Javascript:
document.write((1732584193 << 5)+"<br />");
document.write((125 << 5)+"<br />");
output:
-391880672
4000
In PHP:
echo (1732584193 << 5)."<br />";
echo (125 << 5)."<br />";
output:
55442694176
4000
解决办法:
$a = 1732584193;
$b = $a << 5;
$c = (($a << 5) << 32) >> 32;
echo $a, "\n"; # 1732584193
echo $b, "\n"; # 55442694176
echo $c, "\n"; # -391880672
转载:https://stackoverflow.com/questions/25587803/why-lshift-in-javascript-and-php-are-not-the-same