class Solution {
public:
int hammingWeight(uint32_t n) {
int ans = 0;
while (n != 0) {
if (n % 2)ans++;
n /= 2;
}
return ans;
}
};
">>>"无符号右移
操作规则:无论正负数,前面补零。
">>"右移
操作规则:正数前面补零,负数前面补1
"<<"左移
操作规则:无论正负数,后面补零。