我给你一个自愿省略的答案gmp_strval(gmp_init(strtoupper($hash32), 32), 16);
,它只适用于你的服务器中安装的GMP 。
function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
if ($fromBaseInput==$toBaseInput) return $numberInput;
$fromBase = str_split($fromBaseInput,1);
$toBase = str_split($toBaseInput,1);
$number = str_split($numberInput,1);
$fromLen=strlen($fromBaseInput);
$toLen=strlen($toBaseInput);
$numberLen=strlen($numberInput);
$retval='';
if ($toBaseInput == '0123456789')
{
$retval=0;
for ($i = 1;$i <= $numberLen; $i++)
$retval = bcadd($retval, bcmul(array_search($number[$i-1], $fromBase),bcpow($fromLen,$numberLen-$i)));
return $retval;
}
if ($fromBaseInput != '0123456789')
$base10=convBase($numberInput, $fromBaseInput, '0123456789');
else
$base10 = $numberInput;
if ($base10<strlen($toBaseInput))
return $toBase[$base10];
while($base10 != '0')
{
$retval = $toBase[bcmod($base10,$toLen)].$retval;
$base10 = bcdiv($base10,$toLen,0);
}
return $retval;
}
这个函数,在这里找到,“将任意大的数字从任何基数转换为任何基数”。您只需要从base 32转换为base 16,因此:
base 32 字母表是:ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
$hash32='IXE2K3JMCPUZWTW3YQZZOIB5XD6KZIEQ';
$hash16=convBase($hash32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', '0123456789ABCDEF');
//$hash16='45C9A56D2C13E99B4EDBC43397203DB8FCACA090'
这里的问题是对base_convert
大量数字处理不当。