Skip to content

Instantly share code, notes, and snippets.

@limboinf
Created March 28, 2016 08:43
Show Gist options
  • Save limboinf/aec60d19d7086fb33218 to your computer and use it in GitHub Desktop.
Save limboinf/aec60d19d7086fb33218 to your computer and use it in GitHub Desktop.
bit operation to check even
/*
** 右移计算值为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