Created
April 15, 2015 01:15
-
-
Save ksvbka/5f8c9391be4e4547915a to your computer and use it in GitHub Desktop.
Bit algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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