191.Number of 1 Bits

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int res = 0;
        for (int i = 0; i < 32; ++i) {
           res+=0x1&(n>>i);
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/smallredness/p/10696342.html