note 104311 added to function.decbin

From: Date: Wed, 08 Jun 2011 11:22:20 +0000
Subject: note 104311 added to function.decbin
Groups: php.notes 
Request: Send a blank email to php-notes+get-180326@lists.php.net to get a copy of this message
Here's a generic binary output formatter. It is based on the function in above comments, but lets you specify how many bits your want formatted. /** * Output an x bit string representing a binary value. * Default is 8 bits ie. 0000 0000 * eg. fmt_binary($x,32) : output a 32-bit binary representation of $x * @param string $x x-bit formatted binary */ function fmt_binary($x, $numbits = 8) { // Convert to binary $bin = decbin($x); $bin = substr(str_repeat(0,$numbits),0,$numbits - strlen($bin)) . $bin; // Split into x 4-bits long $rtnval = ''; for ($x = 0; $x < $numbits/4; $x++) { $rtnval .= ' ' . substr($bin,$x*4,4); } // Get rid of first space. return ltrim($rtnval); } ---- Server IP: 69.147.83.197 Probable Submitter: 58.161.42.254 ---- Manual Page -- http://www.php.net/manual/en/function.decbin.php Edit -- https://master.php.net/note/edit/104311 Del: integrated -- https://master.php.net/note/delete/104311/integrated Del: useless -- https://master.php.net/note/delete/104311/useless Del: bad code -- https://master.php.net/note/delete/104311/bad+code Del: spam -- https://master.php.net/note/delete/104311/spam Del: non-english -- https://master.php.net/note/delete/104311/non-english Del: in docs -- https://master.php.net/note/delete/104311/in+docs Del: other reasons-- https://master.php.net/note/delete/104311 Reject -- https://master.php.net/note/reject/104311 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180326) next »