// 统计一个数二进制中的1的个数 #include <stdio.h> int count(int a) { int count = 0; while (a) { count++; a = a & (a - 1); } return count; } int main() { printf("%d ", count(10)); printf("%d ", count(0)); printf("%d ", count(-1)); return 0; }