note 110167 deleted from function.hexdec by googleguy
| From: | googleguy@php.net | Date: | Tue, 25 Sep 2012 19:04:18 +0000 |
| Subject: | note 110167 deleted from function.hexdec by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191017@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
//-------------------------------------------------------------//
//---This function converts from HEX to 32bit IEEE 754 Float---//
//-------------------------------------------------------------//
//I think it is usefull and it´s missing in php
function hex2float($number)
{
$bin = hexdec($number);
$sign=($bin & 0x80000000)>>31;
$exp = (($bin & 0x7F800000)>>23)-127;
$coma = ($bin & 0x7FFFFF)>>(23-$exp);
$result=$coma | (0x1<<$exp);
if($sign==1)
{$result = $result*(-1);}
return $result;
}
//--------------usage---------------//
// number $a = hex2float(string $b);
//-------------example--------------//
echo hex2float("4405c000");
//output -> 535