Java Utililty Methods BigInteger Value Check

List of utility methods to do BigInteger Value Check

Description

The list of methods to do BigInteger Value Check are organized into topic(s).

Method

booleanisPowerOfTwo(BigInteger bintValue)
is Power Of Two
int bitIndex = bintValue.getLowestSetBit();
if (bitIndex < 0) {
    return false;
return bintValue.clearBit(bitIndex).equals(BigInteger.ZERO);
booleanisPowerOfTwo(BigInteger x)
is Power Of Two
return x.signum() > 0 && x.getLowestSetBit() == x.bitLength() - 1;
booleanisRootInQuadraticResidues(BigInteger n, BigInteger p)
is Root In Quadratic Residues
BigInteger tow = BigInteger.valueOf(2);
BigInteger x = n.mod(p);
if (p.equals(tow)) {
    return x.mod(tow).equals(BigInteger.ONE);
BigInteger exponent = p.subtract(BigInteger.ONE).divide(tow);
return x.modPow(exponent, p).equals(BigInteger.ONE);
booleanisSqrtXXX(BigInteger n, BigInteger root)
is Sqrt XXX
final BigInteger lowerBound = root.pow(2);
final BigInteger upperBound = root.add(BigInteger.ONE).pow(2);
return lowerBound.compareTo(n) <= 0 && n.compareTo(upperBound) < 0;
booleanisZero(BigInteger value)
is Zero
return value.compareTo(BigInteger.ZERO) == 0;