码迷,mamicode.com
首页 > 其他好文 > 详细

191. Number of 1 Bits

时间:2020-05-10 21:37:41      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:space   pac   nbsp   clu   name   str   pre   mingw   string   

技术图片

 

 

#include<iostream>
#include<string>
using namespace std;
int hammingWeight(uint32_t n) {
    int ans = 0;
    while (n) {
        if (n % 2 == 1) {
            ans += 1;
        }
        n = n / 2;
    }
    return ans;
}

int main() {
    uint32_t a = 128;
    cout << hammingWeight(a) << endl;
    return 0;
}

 

191. Number of 1 Bits

标签:space   pac   nbsp   clu   name   str   pre   mingw   string   

原文地址:https://www.cnblogs.com/luo-c/p/12864808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!