思路:
// @Title: 位 1 的个数 (位 1 的个数)
// @Author: qisiii
// @Date: 2022-02-20 14:22:21
// @Runtime: 0 ms
// @Memory: 38.3 MB
// @comment:
// @flag:
public class Solution {
// you need to treat n as an unsigned value
public static int hammingWeight(int n) {
int temp=n;
int count=0;
while(temp!=0){
if((temp&1)==1){
count++;
}
temp=temp>>>1;
}
return count;
}
}