//给定一个非负整数num,不用循环,返回>=num,并离num最近的,2的某次方
public static final int tableSizeFor(int n) {
n--;
n |=n >>>1;//>>>不带符号右移
n |=n >>>2;
n |=n >>>4;
n |=n >>>8;
n |=n >>>16;//打满,至此int32位,全打满
return (n < 0)? 1 : n+1;//负数的最近2次方数为1,正数打满所有为再+1
}
public static void main(String[] args) {
int cap = 120;
System.out.println(tableSizeFor(cap));
}