//下一个最大的二次幂 inline int nextPowerOfTwo(int x){ x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); return x + 1; } //判断是不是2的幂 inline bool isPowerOfTwo(int x){ bool result = x > 0 && (x & (x - 1)) == 0; return result; }
//下一个最大的二次幂 inline int nextPowerOfTwo(int x){ x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); return x + 1; } //判断是不是2的幂 inline bool isPowerOfTwo(int x){ bool result = x > 0 && (x & (x - 1)) == 0; return result; }