note 92363 added to function.bindec
| From: | Nitrogen at osu1 dot php dot net | Date: | Tue, 21 Jul 2009 14:27:39 +0000 |
| Subject: | note 92363 added to function.bindec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158547@lists.php.net to get a copy of this message | ||
Binary to Decimal conversion using the BCMath extension..
<?php
function BCBin2Dec($Input='') {
$Output='0';
if(preg_match("/^[01]+$/",$Input)) {
for($i=0;$i<strlen($Input);$i++)
$Output=BCAdd(BCMul($Output,'2'),$Input{$i});
}
return($Output);
}
?>
This will simply convert from Base-2 to Base-10 using BCMath (arbitrary precision calculation).
See also: my 'BCDec2Bin' function on the 'decbin' document.
Enjoy,
Nitrogen.
----
Server IP: 92.48.74.199
Probable Submitter: 217.42.173.142
----
Manual Page -- http://www.php.net/manual/en/function.bindec.php
Edit -- https://master.php.net/note/edit/92363
Del: integrated -- https://master.php.net/note/delete/92363/integrated
Del: useless -- https://master.php.net/note/delete/92363/useless
Del: bad code -- https://master.php.net/note/delete/92363/bad+code
Del: spam -- https://master.php.net/note/delete/92363/spam
Del: non-english -- https://master.php.net/note/delete/92363/non-english
Del: in docs -- https://master.php.net/note/delete/92363/in+docs
Del: other reasons-- https://master.php.net/note/delete/92363
Reject -- https://master.php.net/note/reject/92363
Search -- https://master.php.net/manage/user-notes.php