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;
}
posted @ 2024-09-28 14:05  寻找繁星  阅读(1)  评论(0编辑  收藏  举报