Created
March 28, 2016 08:43
-
-
Save limboinf/aec60d19d7086fb33218 to your computer and use it in GitHub Desktop.
bit operation to check even
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
/* | |
** 右移计算值为1的位的个数 | |
** 接收一个无符号参数,避免右移歧义 | |
*/ | |
int | |
count_one_bits(unsigned value) | |
{ | |
int ones; | |
for (ones = 0; value != 0; value = value >> 1) { | |
printf("%d\n", value); | |
if (value % 2 != 0) { | |
ones+=1; | |
} | |
} | |
return ones; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment