note 102205 added to function.sprintf
| From: | carmageddon at gmail dot com | Date: | Wed, 02 Feb 2011 14:38:25 +0000 |
| Subject: | note 102205 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176596@lists.php.net to get a copy of this message | ||
If you want to convert a decimal (integer) number into constant length binary number in lets say 9
bits, use this:
$binary = sprintf('%08b', $number );
for example:
<?php
$bin = sprintf('%08b',511 );
echo $bin."\n";
?>
would output 111111111
And 2 would output 00000010
I know the leading zeros are useful to me, perhaps they are to someone else too.
----
Server IP: 69.147.83.197
Probable Submitter: 109.226.18.250
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/102205
Del: integrated -- https://master.php.net/note/delete/102205/integrated
Del: useless -- https://master.php.net/note/delete/102205/useless
Del: bad code -- https://master.php.net/note/delete/102205/bad+code
Del: spam -- https://master.php.net/note/delete/102205/spam
Del: non-english -- https://master.php.net/note/delete/102205/non-english
Del: in docs -- https://master.php.net/note/delete/102205/in+docs
Del: other reasons-- https://master.php.net/note/delete/102205
Reject -- https://master.php.net/note/reject/102205
Search -- https://master.php.net/manage/user-notes.php