题解 | #二进制中1的个数#
二进制中1的个数
https://www.nowcoder.com/practice/8ee967e43c2c4ec193b040ea7fbb10b8
public class Solution { public int NumberOf1(int n) { int num = 0 ; int n2 = n; if (n < 0) { n2 = -1 * n2;//负数取余为负数去符号后的正数取余 } if (n2 % 2 == 1) { num ++; } while (n != 0) { n = n >>> 1;//无符号右移 if (n % 2 == 1) { num ++; } } return num; } }