note 32519 added to function.bindec

From: Date: Fri, 30 May 2003 03:37:45 +0000
Subject: note 32519 added to function.bindec
Groups: php.notes 
Request: Send a blank email to php-notes+get-49387@lists.php.net to get a copy of this message
## calculate the dec with the "shift-method" ## function bin2dec($binary_code){ for($i=1;$i<=strlen($binary_code);$i++){ if ($binary_code{$i-1} == "1"){ $x=(2*$x)+1; } else{ $x=2*$x; } } $calculated_dec=$x; return $calculated_dec; } ## Example ## 1011 -> 11 | End: x = (x*2)+1 101 -> 5 | .. x = (x*2)+1 10 -> 2 | .. x = x*2 1 -> 1 | Start: x = 1 (0 -> 0) | ---- Manual Page -- http://www.php.net/manual/en/function.bindec.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32519 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32519&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32519&report=yes

« previous php.notes (#49387) next »