C语言找到下一个2的幂
详情:https://seekstar.github.io/2020/03/22/c语言取二进制最高位1/
uint32_t next_pow_of_2(uint32_t x) {
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
return x + 1;
}
详情:https://seekstar.github.io/2020/03/22/c语言取二进制最高位1/
uint32_t next_pow_of_2(uint32_t x) {
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
return x + 1;
}