note 98272 added to language.types.float

From: Date: Sat, 05 Jun 2010 20:43:46 +0000
Subject: note 98272 added to language.types.float
Groups: php.notes 
Request: Send a blank email to php-notes+get-169910@lists.php.net to get a copy of this message
The was talk about "converting" 32 and 64 bit IEEE754 binary numbers to PHP float. The issue isn't as much converting, since they are already in binary form, as it is casting. PHP doesn't allow direct accessing of memory, but you can still get around a bit. The right was to read floats (32 and 64 bit) is this: <?php $binarydata32 = pack('H*','0EC0A14A'); $float32 = unpack("f", $binarydata32); $binarydata64 = pack('H*','000000C001385441'); $float64 = unpack("d", $binarydata64); var_dump($float32,$float64,$float32==$float64); ?> The result of dump(): <?php array(1) { [1]=> float(5300231) } array(1) { [1]=> float(5300231) } bool(true) ?> Note: mind the Big and Little endian boys ---- Server IP: 69.147.83.197 Probable Submitter: 95.176.128.194 ---- Manual Page -- http://www.php.net/manual/en/language.types.float.php Edit -- https://master.php.net/note/edit/98272 Del: integrated -- https://master.php.net/note/delete/98272/integrated Del: useless -- https://master.php.net/note/delete/98272/useless Del: bad code -- https://master.php.net/note/delete/98272/bad+code Del: spam -- https://master.php.net/note/delete/98272/spam Del: non-english -- https://master.php.net/note/delete/98272/non-english Del: in docs -- https://master.php.net/note/delete/98272/in+docs Del: other reasons-- https://master.php.net/note/delete/98272 Reject -- https://master.php.net/note/reject/98272 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169910) next »