note 92368 added to function.decbin

From: Date: Tue, 21 Jul 2009 17:30:59 +0000
Subject: note 92368 added to function.decbin
Groups: php.notes 
Request: Send a blank email to php-notes+get-158553@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: 69.147.83.197 Probable Submitter: 187.58.239.189 ---- Manual Page -- http://www.php.net/manual/en/function.decbin.php Edit -- https://master.php.net/note/edit/92368 Del: integrated -- https://master.php.net/note/delete/92368/integrated Del: useless -- https://master.php.net/note/delete/92368/useless Del: bad code -- https://master.php.net/note/delete/92368/bad+code Del: spam -- https://master.php.net/note/delete/92368/spam Del: non-english -- https://master.php.net/note/delete/92368/non-english Del: in docs -- https://master.php.net/note/delete/92368/in+docs Del: other reasons-- https://master.php.net/note/delete/92368 Reject -- https://master.php.net/note/reject/92368 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158553) next »