Friday, January 7, 2011

Bit Operation #4

Let's think about how we can count the bit set to 1 in an integer?
 

int bitCount(unsigned int a)
{
int count = 0;
while (a != 0)
{
count += a & 0x01;
a >>= 1;
}
return count;
}
Then, how can we optimize the process to work with several integers?

No comments: