Reading the decimal value of little endian in PHP -
i'm reading 6 bytes in little endian binary file using
$data = fread($fp, 6); unpack("v", $data);
the result 1152664389 , in hex 0x44b44345
now result in little endian , has decimal number. in delphi, able decimal number using function:
var myint:integer; s:single; begin myint:= 1152664389; // same myint:= $44b44345; s:= psingle(@myint)^;
and output of s 1442.102.. number im looking for...
i searched way in php got lost.
please help,
thanks
okay, bit confused. wanted retrieve little endian number binary file convert float.
so steps were:
1) read bytes , unpack using $number = unpack("v", $data); 2) convert $number decimal using dechex. 3) use following function convert hex float:
function hexto32float($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); }
thanks again.
Comments
Post a Comment