这个程序是在程序员面试宝典里看到的,在这里记下来以方便学习。
#include<iostream>
using namespace std;
int func(int x)
{
int count = 0;
while(x)
{
count++;
x=x&(x-1);
}
return count;
}
int main()
{
cout<<func(999)<<endl;
return 0;
}
这个程序是在程序员面试宝典里看到的,在这里记下来以方便学习。
#include<iostream>
using namespace std;
int func(int x)
{
int count = 0;
while(x)
{
count++;
x=x&(x-1);
}
return count;
}
int main()
{
cout<<func(999)<<endl;
return 0;
}