十进制数转化成二进制后包含一的数量(c++)

#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;
      system("pause");
      return 0;
}

原文地址:https://www.cnblogs.com/skylar/p/3594258.html