note 118458 added to function.bindec

From: Date: Wed, 09 Dec 2015 20:54:46 +0000
Subject: note 118458 added to function.bindec
Groups: php.notes 
Request: Send a blank email to php-notes+get-204317@lists.php.net to get a copy of this message
<?php //binfloat (For single precision floating point numbers) //IEE754 //https://en.wikipedia.org/wiki/Single-precision_floating-point_format function binfloat(Array $num){ $sign = $num[0] ? 1 : -1; //1 bit $exponent = pow(2,bindec(implode('',array_slice($num,1,8)))-127); $fraction = array_slice($num,9,count($num)); //23 bits $fracSum = 1; for($i=0;$i<23;$i++){ $fracSum += $fraction[$i] * pow(2,-1-$i); } return $fracSum*$exponent; } $num = isset($_GET['num']) ? $_GET['num'] : '00111110001000000000000000000000'; if(strlen($num)<32){ echo "Invalid binary number $num\n"; exit(1); } $num = str_split($num); echo sprintf('Num is: [%s]%s',implode('',$num),"\n"); echo sprintf('Result is: %s%s',binfloat($num),"\n"); ---- Server IP: 72.52.91.14 Probable Submitter: 190.247.89.52 ---- Manual Page -- http://php.net/manual/en/function.bindec.php Edit -- https://master.php.net/note/edit/118458 Del: integrated -- https://master.php.net/note/delete/118458/integrated Del: useless -- https://master.php.net/note/delete/118458/useless Del: bad code -- https://master.php.net/note/delete/118458/bad+code Del: spam -- https://master.php.net/note/delete/118458/spam Del: non-english -- https://master.php.net/note/delete/118458/non-english Del: in docs -- https://master.php.net/note/delete/118458/in+docs Del: other reasons-- https://master.php.net/note/delete/118458 Reject -- https://master.php.net/note/reject/118458 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204317) next »