问题是
that The largest number that can be converted is ... 4294967295 – 因此它不适合你.
This answer在快速测试期间为我工作,假设您在服务器上安装了bcmath,并且您可以将该数字作为字符串开头.如果你不能,即它以数字变量开始生命,你将立即达到PHP’s float limit.
// Credit: joost at bingopaleis dot com
// Input: A decimal number as a String.
// Output: The equivalent hexadecimal number as a String.
function dec2hex($number)
{
$hexvalues = array('0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F');
$hexval = '';
while($number != '0')
{
$hexval = $hexvalues[bcmod($number,'16')].$hexval;
$number = bcdiv($number,'16',0);
}
return $hexval;
}
例:
$number = '114483222461061018757513232564608398004'; // Important: already a string!
var_dump(dec2hex($number)); // string(32) "5620AAA80D50FD70496983E2A39972B4"
确保将字符串传递给该函数,而不是数字变量.在您在问题中提供的示例中,看起来您最初可以将该数字作为字符串获取,因此如果您安装了bc,则应该可以使用.