Skip to content

Instantly share code, notes, and snippets.

@shumon84
Created March 25, 2017 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shumon84/80d8b366e9c1541871c570f3fc00b712 to your computer and use it in GitHub Desktop.
Save shumon84/80d8b366e9c1541871c570f3fc00b712 to your computer and use it in GitHub Desktop.
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