Etienne Kneuss

home » repository » php » sample » bitmask.php
Tree:
school
mp3
php
sample
sort.php
bitmask.php
disable_magic_quotes.php
BB.php
regex_urls.php
highlight_patch.php
publications
Math_Derivative
Math_Expression
ircbot
php.net
images
dump

Source code raw phps

    <?php /**  * bitmask decompose  * --  * A simple decomposition of bitmasks.  * example: 72 -> array( 8, 64 );  */ function bitmask_decompose($bitmask)  {     $modes = array();     $a = 1;     while ($bitmask > 0) {         if (($a & $bitmask) != 0) {             $modes[] = $a & $bitmask;         }         $bitmask &= ~$a;         $a <<= 1;     }     return $modes; } ?>

Comments

29.01.2007 #1 noemail

I needed this tonite. Thanks!

25.08.2008 #2 GentooDude

Nice! I was looking to do something like this and forgot about the decompose part and wondered why it wouldn't work... thanks :)

Add a comment

Username:

Spam Challenge: 9+18=?

Comment: