位运算
📌 二进制中1的个数
· ☕ 1 分钟
1 2 3 4 5 6 7 8 int hammingWeight(uint32_t n) { short count = 0; while(n){ if(n%2 == 1) count++; n = n >> 1; } return count; }