note 111205 deleted from language.types.float by googleguy

From: Date: Fri, 25 Jan 2013 20:36:52 +0000
Subject: note 111205 deleted from language.types.float by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193393@lists.php.net to get a copy of this message
Note Submitter: jack at surfacefinishtech dot com ---- /** hex2float * (Convert 8 digit hexadecimal value to float (single-precision 32bits) * Accepts 8 digit hexadecimal values in a string * @usage: * hex2float32n("429241f0"); returns -> "73.128784179688" * */ function hex2float($number) { $binfinal = sprintf("%032b",hexdec($number)); $sign = substr($binfinal, 0, 1); $exp = substr($binfinal, 1, 8); $mantissa = "1".substr($binfinal, 9); $mantissa = str_split($mantissa); $exp = bindec($exp)-127; $significand=0; for ($i = 0; $i < 24; $i++) { $significand += (1 / pow(2,$i))*$mantissa[$i]; } return $significand * pow(2,$exp) * ($sign*-2+1); }

« previous php.notes (#193393) next »