note 10685 modified in function.decbin by vincent

From: Date: Tue, 12 Aug 2003 10:51:35 +0000
Subject: note 10685 modified in function.decbin by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53991@lists.php.net to get a copy of this message
Here's a little binary for counting on your fingers up to 1023 (from 0). It formats/pads the binary number like you wanted. <pre> &lt;?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"; ?> </pre> 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... --was-- To: daduke@dataway.ch <br> Here's a little binary for counting on your fingers up to 1023 (from 0). It formats/pads the binary number like you wanted. <pre> &lt;?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"; ?> </pre> 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... http://www.php.net/manual/en/function.decbin.php

« previous php.notes (#53991) next »