Java Utililty Methods BigInteger Calculate

List of utility methods to do BigInteger Calculate

Description

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

Method

StringencodeToBase62(BigInteger num)
encode To Base
BigInteger value = BigInteger.ZERO.add(num);
String result = "";
while (!value.equals(BigInteger.ZERO)) {
    result = BASE62_DIGITS.charAt(value.mod(SIXTY_TWO).intValue()) + result;
    value = value.divide(SIXTY_TWO);
return result;
StringencodeToString(final BigInteger input)
Big integer to much smaller string encoding
final BigInteger encodeLength = BigInteger.valueOf(ENCODE.length());
BigInteger running = input;
BigInteger mod;
final StringBuilder result = new StringBuilder(64);
result.append(running.intValue() == 0 ? "0" : "");
while (running.longValue() != 0) {
    mod = running.remainder(encodeLength);
    result.append(ENCODE.substring(mod.intValue(), mod.intValue() + 1));
...
StringencodeURL(BigInteger id)
encode URL
StringBuilder str = new StringBuilder();
BigInteger primaryKey = new BigInteger(String.valueOf(id));
while (primaryKey.compareTo(BigInteger.ZERO) == 1) {
    str.insert(0, ALPHABET.charAt(primaryKey.mod(BASE).intValue()));
    primaryKey = primaryKey.divide(BASE);
return str.toString();
booleanequal(BigInteger int1, BigInteger int2)
equal
if (int1.compareTo(int2) == 0) {
    return true;
return false;
booleanequals(BigInteger[] a, BigInteger[] b)
Checks if two BigInteger arrays contain the same entries
int flag = 0;
if (a.length != b.length) {
    return false;
for (int i = 0; i < a.length; i++) {
    flag |= a[i].compareTo(b[i]);
return flag == 0;
...
booleanextractBoolean(BigInteger bi, int index)
extract Boolean
return bi.testBit(index);
floatextractFloat(BigInteger bi, int start, int end, int decimal)
extract Float
int intpart = extractInt(bi, start + decimal, end);
int decpart = extractInt(bi, start, start + decimal);
float decf = decpart;
while (decf >= 1.0) {
    decf = decf / 10;
float ret = intpart + decf;
return ret;
...
intextractInt(BigInteger bi, int start, int end)
extract Int
bi = bi.shiftRight(start);
int foo = (int) Math.pow(2, end - start) - 1;
BigInteger mask = BigInteger.valueOf(foo);
bi = bi.and(mask);
return bi.intValue();
voidfill(BigInteger[] array, BigInteger value)
Fill the given BigInteger array with the given value.
for (int i = array.length - 1; i >= 0; i--) {
    array[i] = value;
BigIntegerfirst(BigInteger i, BigInteger j)
This method is used in the RAC implementation of postfix ++ and -- over \bigint's.
return i;