Here you can find the source of isPowerOfTwo(BigInteger x)
public static boolean isPowerOfTwo(BigInteger x)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static boolean isPowerOfTwo(BigInteger x) { return x.signum() > 0 && x.getLowestSetBit() == x.bitLength() - 1; }//from ww w . ja v a 2s. co m /** * Returns {@code true} if {@code x} represents a power of two. * * <p>This differs from {@code Integer.bitCount(x) == 1}, because * {@code Integer.bitCount(Integer.MIN_VALUE) == 1}, but {@link Integer#MIN_VALUE} is not a power * of two. */ public static boolean isPowerOfTwo(int x) { return x > 0 & (x & (x - 1)) == 0; } }