note 92362 added to function.decbin

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

« previous php.notes (#158546) next »