note 87039 added to function.bindec

From: Date: Sun, 16 Nov 2008 12:40:28 +0000
Subject: note 87039 added to function.bindec
Groups: php.notes 
Request: Send a blank email to php-notes+get-146593@lists.php.net to get a copy of this message
for converting fractions : eg : 1001.1101 function BinaryToDecimal($binary){ $binary=trim($binary); if (strstr($binary,'.')){ $split=explode('.',$binary); $integer=$split[0]; $fraction=$split[1]; $digits=str_split($fraction); $num=sizeof($digits); for ($i=1; $i<=$num;$i++){ if ($digits[$i-1]>1){ echo '<script>alert("Enter Binary Digits Only {0,1}\n \n eg: 11001 or 11001.011");history.go(-1)</script> '; } $exponent=pow(2,-$i); $fraction_result+=$digits[$i-1]*$exponent; } }else{ $integer=$binary; } $splits=str_split($integer); $num=sizeof($splits)-1; $i=$num; foreach($splits as $digits){ if ($digits>1){ echo '<script>alert("Enter Binary Digits Only {0,1}\n \n eg: 11001 or 11001.011");history.go(-1)</script> '; } $exponent=pow(2,$i); $integer_result+=$digits*$exponent; $i--; } if($fraction_result){ $result=$integer_result+$fraction_result; }else { $result=$integer_result; } return $result ; } ---- Server IP: 69.147.83.197 Probable Submitter: 41.233.34.204 ---- Manual Page -- http://www.php.net/manual/en/function.bindec.php Edit -- https://master.php.net/note/edit/87039 Del: integrated -- https://master.php.net/note/delete/87039/integrated Del: useless -- https://master.php.net/note/delete/87039/useless Del: bad code -- https://master.php.net/note/delete/87039/bad+code Del: spam -- https://master.php.net/note/delete/87039/spam Del: non-english -- https://master.php.net/note/delete/87039/non-english Del: in docs -- https://master.php.net/note/delete/87039/in+docs Del: other reasons-- https://master.php.net/note/delete/87039 Reject -- https://master.php.net/note/reject/87039 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146593) next »