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

booleanisIntValue(BigInteger bi)
Checks, whether a BigInteger my be converted to an integer, i.e.
if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0)
    return false;
if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0)
    return false;
return true;
booleanisLessThan(BigInteger valueA, BigInteger valueB)
is Less Than
return valueA.compareTo(valueB) < 0;
booleanisLong(BigInteger number)
is Long
long i = number.longValue();
BigInteger b = new BigInteger(String.valueOf(i));
return number.equals(b);
booleanisMersenneNumber(BigInteger n)
Method to check if a given number is a Mersenne number (primality of the number is not checked).
if (n.signum() < 0)
    return false;
byte bytes[] = n.toByteArray();
byte b = bytes[0];
if ((b & (b + 1)) != 0)
    return false;
for (int i = 1; i < bytes.length; i++)
    if (bytes[i] != -1)
...
booleanisNegative(BigInteger i)
is Negative
return i.signum() < 0;
booleanisNumberInRange(String text, BigInteger min, BigInteger max)
Check whether the number is in range [min, max] inclusive.
BigInteger value = null;
try {
    value = new BigInteger(text);
} catch (Exception e) {
    return false;
if (min != null) {
    if (value.compareTo(min) < 0) {
...
booleanisOdd(BigInteger in)
Tests whether a given BigInteger is odd.
return in.testBit(0);
booleanisOdd(BigInteger x)
is Odd
return x.testBit(0);
booleanisPerfectCubic(BigInteger n)
is Perfect Cubic
while (maxCubicInCache.compareTo(n) < 0) {
    Long v = cubicCache.get(maxCubicInCache);
    ++v;
    BigInteger vb = BigInteger.valueOf(v);
    BigInteger k = vb.multiply(vb).multiply(vb);
    cubicCache.put(k, v);
    maxCubicInCache = k;
return cubicCache.containsKey(n);
booleanisPositive(final BigInteger value)
Tests if a given BigInteger value is positive.
if (value == null) {
    return false;
return value.signum() == 1;