📅  最后修改于: 2023-12-03 15:13:39.258000             🧑  作者: Mango
BigIntegerMath isPowerOfTwo()函数是Google Guava库中提供的用于判断BigInteger对象是否为2的幂次方的函数。该函数返回一个布尔值,表示给定的BigInteger对象是否是2的幂次方。
public static boolean isPowerOfTwo(BigInteger x)
import com.google.common.math.BigIntegerMath;
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
BigInteger x = new BigInteger("16");
System.out.println("x is power of two: " + BigIntegerMath.isPowerOfTwo(x));
x = new BigInteger("10");
System.out.println("x is power of two: " + BigIntegerMath.isPowerOfTwo(x));
}
}
输出:
x is power of two: true
x is power of two: false