Skip to content

Instantly share code, notes, and snippets.

@ksvbka
Created April 15, 2015 01:15
Show Gist options
  • Save ksvbka/5f8c9391be4e4547915a to your computer and use it in GitHub Desktop.
Save ksvbka/5f8c9391be4e4547915a to your computer and use it in GitHub Desktop.
Bit algorithm
//count the 1 bits in a int
int count_ones(unsigned int x)
{
int result = 0;
while (x != 0)
result++, x = x & (x-1);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment