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

时间:2014-03-12 05:22:30   收藏:0   阅读:428

#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;
}

十进制数转化成二进制后包含一的数量(c++),布布扣,bubuko.com

原文:http://www.cnblogs.com/skylar/p/3594258.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!