#include <stdio.h>
#include <stdlib.h>
int func(int x)
{
int countx= 0;
while(x){
countx++;
x = x&(x-1);
}
return countx;
}
void main()
{
int result = func(9999);
printf("%d\n",result);
system("pause");
}
//结果为8,9999先转化成二进制,其中中有8个1
#include <stdlib.h>
int func(int x)
{
int countx= 0;
while(x){
countx++;
x = x&(x-1);
}
return countx;
}
void main()
{
int result = func(9999);
printf("%d\n",result);
system("pause");
}
//结果为8,9999先转化成二进制,其中中有8个1