统计数中二进制表达式中1的个数

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int count = 0;
    while(n)
    {
        n = n&(n-1);
        count++;

    }
    cout << count << endl;
    return 0;
}

 

posted @ 2016-10-14 22:40  prog123  阅读(190)  评论(0编辑  收藏  举报