原题链接 代码如下: class Solution { public: int hammingWeight(uint32_t n) { int ans = 0; for(int i = 0; i < 32; i ++) if(n >> i & 1) ans ++; return ans; } };