note 10685 deleted from function.decbin by danielc

From: Date: Mon, 27 Apr 2009 02:08:53 +0000
Subject: note 10685 deleted from function.decbin by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153794@lists.php.net to get a copy of this message
Note Submitter: oubiwann at yahoo dot com Reason: 2 ---- Here's a little binary for counting on your fingers up to 1023 (from 0). It formats/pads the binary number like you wanted. <?php print "<pre>Dec : Finger Positions\n"; print "---- : ----------------\n"; for ( $i=0; strlen($bin) <=10; ++$i ) { $bin = decbin($i); $output = sprintf("%04d : ", $i); $bin_temp = $bin; while ( strlen($bin_temp) < 10 ) { $bin_temp = "0" . $bin_temp; } print $output . $bin_temp . "\n"; } print "</pre>\n"; ?> I tried using sprintf("%04d : %10d", $i, $bin) and sprintf("%04d : %10d", $i, $bin + 0), the later an attempt to force the string to act as a number, but neither worked. Maybe it was me...

« previous php.notes (#153794) next »