Home > Backend Development > PHP Tutorial > php 中这个用法的浮点运算的函数是什么,该怎么处理

php 中这个用法的浮点运算的函数是什么,该怎么处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:14:03
Original
1282 people have browsed it

php 中这个用法的浮点运算的函数是什么
php 中这个用法的浮点运算的函数是什么

请先看看百度百科里的浮点运算例子

http://wenku.baidu.com/view/9ba120a108a1284ac85043d8.html?re=view

也就是把 十六进制的 42C88000 
使用IEEE754标准的32位浮点数格式 算出来结果等于 100.25

把十六进制的C1C90000 算出是 -25.125 

有没有现成的函数?

帮我写个例子, 万分感激


谢谢

------解决思路----------------------

  <br />function hexToDecFloat($strHex) {<br />	$v = hexdec($strHex);<br />	$x = ($v & ((1 << 23) - 1)) + (1 << 23) * ($v >> 31 <br><font color='#FF8000'>------解决思路----------------------</font><br> 1);<br />	$exp = ($v >> 23 & 0xFF) - 127;<br />	return $x * pow(2, $exp - 23);<br />}<br />$a='42C88000 ';<br />echo hexToDecFloat($a);<br /> 
Copy after login



等于100.25
------解决思路----------------------
$s = '42C88000';<br />echo current(unpack('f', pack('V', hexdec($s))));<br />
Copy after login
100.25
$s = 'C1C90000';<br />echo current(unpack('f', pack('V', hexdec($s))));<br />
Copy after login
-25.125

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template