#include <stdio.h>
int bitcount1(unsigned x)
{
int b;
for (b = 0; x != 0; x >>= 1)
if (x & 01)
++b;
return b;
}
int bitcount2(unsigned x)
{
int b = 0;
while (x)
{
++b;
x &= (x - 1);
}
return b;
}
int main()
{
int x = 0x15;
int y = 0x5;
printf("x = %d\n", bitcount1(x));
printf("y = %d\n", bitcount2(y));
return 0;
}
bitcount
最新推荐文章于 2023-06-29 14:04:08 发布