一条语句判断数x是否2的n次幂 return !(x & (x - 1)); 求取十进制数字元素1的个数 int fun(int x) { int count = 0; int i, j, k; /方法2 负数不可计算,需要改进/ while (x != 0){ if (x & 1 == 1) count++; x = x >> 1; } /方法1/ while (x != 0){ x = x&(x - 1); count++; } return count; } 运算过程: https://blog.csdn.net/csdn_kou/article/details/79764559