#include <iostream>
#include <cstdlib>
int fun(int x);
int main()
{
std::cout << fun(9999) << std::endl;
return EXIT_SUCCESS;
}
int fun( int x )
{
int count(0);
while (x)
{
++count;
x = x&(x-1);
}
return count;
}
//函数的功能:
x的二进制中包含1的数量
#include <iostream>
#include <cstdlib>
int fun(int x);
int main()
{
std::cout << fun(9999) << std::endl;
return EXIT_SUCCESS;
}
int fun( int x )
{
int count(0);
while (x)
{
++count;
x = x&(x-1);
}
return count;
}
x的二进制中包含1的数量