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
Nice! I was looking to do something like this and forgot about the decompose part and wondered why it wouldn't work... thanks :)
I needed this tonite. Thanks!