class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
for(int i = 0; i < 32 ;i++){
//n与2^i相与,若此位为0,则与运算结果为0
if(n & (1 << i)) res++;
}
return res;
}
};
class Solution {
public:
int hammingWeight(uint32_t n) {
int res = 0;
for(int i = 0; i < 32 ;i++){
//n与2^i相与,若此位为0,则与运算结果为0
if(n & (1 << i)) res++;
}
return res;
}
};