#include <stdio.h>
#include <stdlib.h>
int main()
{
int bitscount(unsigned x);
printf("%d",bitscount(252));
return 0;
}
//可参照bitDelete函数(将无符号整形数最右边为1的一位删除),在上一
//篇博文有讲解
int bitscount(unsigned x)
{
int n = 0;
while(x != 0)
{
x &= (x - 1) ;
n ++;
}
return n;
}
bitscount函数的重写
最新推荐文章于 2021-01-03 11:12:01 发布