bits count c++ code example
Example: count bits c++
//Method 1
int count = 0;
while (n)
{
count++;
n >>= 1;
}
//Method 2
int count = (int)log2(number)+1;
//Method 1
int count = 0;
while (n)
{
count++;
n >>= 1;
}
//Method 2
int count = (int)log2(number)+1;