Check if you are looking for bitcount in the following way...
#include <stdio.h>
int bitcount(int n)
{
int counter = 0;
while(n) {
counter ++;
n &= (n - 1);
}
return counter;
}
main()
{
int i;
for(i=0;i<20;i++)
printf("0x%x -- %d\n", i, bitcount(i));
}