#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(9999)<<endl;
return 0;
}
答案:8
本题目func函数返回值是形参x转化的二进制包含1的数量9999--->10011100001111
原文:http://www.cnblogs.com/c-python/p/4439274.html