41.位1的个数
题目内容:
代码及思路:
class Solution {
public:
int hammingWeight(uint32_t n) {
int count=0;
//从右端开始判断,是否为1,然后将数字右移1位,以此类推
while(n!=0)
{
if(n%2==1)
count++;
n=n>>1;
}
return count;
}
};