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

booleanfirstLtSecond(BigInteger first, BigInteger second)
first Lt Second
return first.compareTo(second) == -1;
BigIntegergcd(BigInteger a, BigInteger b)
gcd
if (a.compareTo(b) < 0) {
    BigInteger t = b;
    b = a;
    a = t;
BigInteger r = null;
do {
    r = a.mod(b);
...
BigIntegerGCD(BigInteger x, BigInteger y)
GCD
if (x.equals(BigInteger.ZERO)) {
    return y;
} else if (y.equals(BigInteger.ZERO)) {
    return x;
} else if (isEven(x) && isEven(y)) {
    x = x.shiftRight(1);
    y = y.shiftRight(1);
    return GCD(x, y).shiftLeft(1);
...
BigIntegergcd(BigInteger... values)
Calculates the greatest common divisor of the specified BigInteger big integer numbers.
if (values.length == 0)
    return BigInteger.ONE;
int allSgn = values[0].signum();
BigInteger gcd = values[0];
for (int i = 1; i < values.length; i++) {
    if (allSgn != values[i].signum())
        allSgn = 1;
    if (gcd.signum() == 0 || gcd.equals(BigInteger.ONE))
...
BigIntegergcd(Iterable nums)
gcd
BigInteger ret = null;
for (BigInteger num : nums) {
    if (ret == null) {
        ret = num;
    } else {
        ret = ret.gcd(num);
return ret;
BigIntegergcdEuclides(BigInteger a, BigInteger b)
gcd Euclides
if (b.equals(BigInteger.ZERO)) {
    return a;
return gcdEuclides(b, a.mod(b));
BigInteger[]gcdExtended(BigInteger p, BigInteger q)
gcd Extended
if (q.equals(BigInteger.ZERO))
    return new BigInteger[] { p, BigInteger.ONE, BigInteger.ZERO };
BigInteger[] vector = gcdExtended(q, p.mod(q));
BigInteger d = vector[0];
BigInteger a = vector[2];
BigInteger b = vector[1].subtract(p.divide(q).multiply(vector[2]));
return new BigInteger[] { d, a, b };
StringgetAddressText(BigInteger address)
get Address Text
if (address == null) {
    return "<null>"; 
if (address.compareTo(BigInteger.ZERO) < 0) {
    return address.toString();
String hex = address.toString(16);
return "0x" + "0000000000000000".substring(hex.length() + (address.bitLength() <= 32 ? 8 : 0)) + hex; 
...
byte[]getByteArrayFromBigIntegerArray(Object value)
Convert an instance of our value class into a byte[].
if (value == null) {
    return null;
BigInteger[] a = (BigInteger[]) value;
long[] d = new long[a.length];
for (int i = 0; i < a.length; i++) {
    d[i] = a[i].longValue();
return getByteArrayFromLongArray(d);
byte[]getBytes(BigInteger bi, int minLen)
get Bytes
byte[] ret = bi.toByteArray();
if (ret[0] == 0) {
    byte copy[] = new byte[ret.length - 1];
    System.arraycopy(ret, 1, copy, 0, copy.length);
    ret = copy;
byte copy[] = new byte[minLen];
if (bi.compareTo(BigInteger.ZERO) < 0) {
...