PHP和js位移运算的坑 2021-10-12 PHP JavaScript默认32位,32位操作系统int类型的最大值是 2147483647,超过该数值会溢出 php 64位需要使用pack转化 PHP中pack、unpack的详细用法: JavaScript运行结果 php和js位移运算的坑 PHP运行结果 php和js位移运算的坑 JavaScript 12345function (t) hash33{ for (var e = 0, i = 0, n = t . length; i < n; ++i) e += (e << 5) + t . charCodeAt(i); return 2147483647 & e} PHP 12345678function hash33($t){ for ( $e = 0, $i = 0, $n = strlen($t); $i < $n; ++$i){ $tmp = $e << 5; $tmp = unpack("L",pack("L",$tmp))[1]; $e += $tmp+ uniord(mb_substr($t,$i,1,'utf-8')); } return 2147483647 & $e;} 版权所有,如果转载,请附上本文链接:https://dinghaijun.com/articles/2021/10/php_and_js_pit_of_bit_operation.html Next MySQL 规约