C语言找到下一个2的幂

阅读量: searchstar 2020-03-22 17:51:25
Categories: Tags:

详情:https://seekstar.github.io/2020/03/22/c%E8%AF%AD%E8%A8%80%E5%8F%96%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%9C%80%E9%AB%98%E4%BD%8D1/

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;
}