<?php
function t_charCodeAt($str, $index){
$char = mb_substr($str, $index, 1, 'UTF-8');
if (mb_check_encoding($char, 'UTF-8')) {
$ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
return hexdec(bin2hex($ret));
} else {
return null;
}
}
function t_crc32($g){
$g = urlencode($g);
$e = array();
for ($f = 0; $f < 256; $f++) {
$c = $f;
for ($d = 0; $d < 8; $d++) {
$c = ($c & 1) ? (($c >> 1) & 2147483647) ^ 3988292384 : (($c >> 1) & 2147483647);
}
$e[$f] = $c;
}
for ($f = 0, $c = 4294967295; $f < strlen($g); $f++) {
$c = (($c >> 8) & 16777215) ^ $e[($c & 255) ^ t_charCodeAt($g, $f)];
}
$c ^= 4294967295; // 32位和64位结果不一致,求解决办法!正确结果应该以32位为例!
$prefix = (!is_numeric(substr($c >> 3, 0, 1))) ? substr($c >> 3, 0, 1) : '';
echo $prefix.base_convert($c >> 3, 10, 16);
}
t_crc32('1029409')."\n";
t_crc32('1549058');
32位和64位结果不一致,求解决办法!正确结果应该以32位为例!
:(
1
giuem 2015-06-13 18:39:33 +08:00 via Android 1
32位最大整数是2147483647
|