时间:2021-07-01 10:21:17 帮助过:38人阅读
function hexToDecFloat($strHex) { $v = hexdec($strHex); $x = ($v & ((1 << 23) - 1)) + (1 << 23) * ($v >> 31 | 1); $exp = ($v >> 23 & 0xFF) - 127; return $x * pow(2, $exp - 23);}$a='42C88000 ';echo hexToDecFloat($a);
$s = '42C88000';echo current(unpack('f', pack('V', hexdec($s))));100.25
$s = 'C1C90000';echo current(unpack('f', pack('V', hexdec($s))));-25.125
也可以
$s = 'C1C90000';echo current(unpack('f', pack('H*', join('', array_reverse(str_split($s, 2))))));-25.125
$a = 'C1C90000';echo hexToDecFloat($a);-6.875
谢谢版主大人的帮助.