Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
int count_bits(int n)
{
int i;
int sum=0;
for(i=sizeof(int)*8-1;i>=0;i--)
sum+=(n>>i)&1;
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment