note 92362 deleted from function.decbin by thiago

From: Date: Tue, 21 Jul 2009 14:29:30 +0000
Subject: note 92362 deleted from function.decbin by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158548@lists.php.net to get a copy of this message
Note Submitter: Nitrogen ---- 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.

« previous php.notes (#158548) next »