Re: bit wise math? Is there a function to easily return the bits?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



function bits($num) {
       $bit_array = str_split(strrev(decbin(intval($num))));
       $val_array = array();
       foreach ($bit_array as $pow => $bit) {
               if ($val = $bit * pow(2,$pow))
                       $val_array[] = $val;
       }
       return($val_array);
}

(I wanted to see if I could write it in few LOC.) I wonder if there's a faster way...

jon

blackwater dev wrote:
Is there a php function I can call to pass in a number and get the values
returned?

For example, pass in 7 and get 1,2,4 ?

Thanks!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux