Do anyone know how I can count number of bits in a interger?
What do you mean: check how much memory it uses, or how "long" it is in binary (i.e. 1=>1, 2=>2, 31=>5, 32=>6,...)?
I wanted to count number of bits who are set to 1. Like this:
function bit_count($num) { return strlen(str_replace('0','',decbin($num))); }
Ok, that's fine. One thing: manual suggests use of ereg_replace:
function bit_count($num) { return strlen(ereg_replace("0","",decbin($num))); }