代码改变世界

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

2014-03-11 16:20  大额_skylar  阅读(226)  评论(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(9999)<<endl;
      system("pause");
      return 0;
}