https://zhuanlan.zhihu.com/p/134690309
public static void main(String[] args) {
hightwo(0);
hightwo(7);
hightwo(32);
}
private static void hightwo(int cap) {
int n = cap - 1;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;
System.out.println((n<0) ? 1 : (n+1));
}


本文通过一个具体的Java代码示例介绍了如何使用位运算来找出比一个给定数值大的最小的2的幂次方数。这种方法在算法设计和优化中非常实用,尤其是在处理计算机科学中的数学问题时。
4742

被折叠的 条评论
为什么被折叠?



