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

BigIntegermodPow(BigInteger base, BigInteger e, BigInteger m)
mod Pow
BigInteger result;
result = BigInteger.ONE;
base = base.mod(m);
for (int i = 0; i < e.bitLength(); ++i) {
    if (e.testBit(i)) {
        result = result.multiply(base).mod(m);
    base = base.multiply(base).mod(m);
...
byte[]modPowByte(byte[] arg, BigInteger e, BigInteger n)
mod Pow Byte
BigInteger source = new BigInteger(1, arg);
BigInteger result = source.modPow(e, n);
return getBytesWithoutSign(result);
longmodPowLong(BigInteger n, long exponent, BigInteger modulo)
mod Pow Long
return n.modPow(BigInteger.valueOf(exponent), modulo).longValue();
BigIntegermods(BigInteger v, BigInteger m)
Signed mod.
The value returned lies in range [ -( |m| - 1 ) / 2 ..
int signum = m.signum();
if (signum == 0)
    throw new ArithmeticException("Zero modulus");
if (signum < 0)
    m = m.negate();
v = v.remainder(m);
if (v.compareTo(m.shiftRight(1)) > 0)
    v = v.subtract(m);
...
intmodulus(BigInteger value, BigInteger divider, int modulo, int... weight)
modulus
BigInteger[] temp = new BigInteger[] { value, ZERO };
int result = 0;
for (int i = 0; temp[0].compareTo(ZERO) != 0; i++) {
    temp = temp[0].divideAndRemainder(divider);
    result = result + temp[1].multiply(valueOf(weight[i % weight.length])).intValue();
result = modulo - result % modulo;
return (result >= modulo ? 0 : result);
...
BigIntegermulti_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)
Compute the multi-exponent base^exponent (modulo modulus) .
assert base.length == exponent.length;
BigInteger res = BigInteger.ONE;
for (int i = 0; i < base.length; i++)
    res = res.multiply(base[i].modPow(exponent[i], modulus)).mod(modulus);
return res;
BigIntegermultiply(BigInteger x, BigInteger y)
multiply
final int bitLengthX = x.bitLength();
final int bitLengthY = y.bitLength();
if (bitLengthX <= 256 || bitLengthY <= 256 || addInts(bitLengthX, bitLengthY) <= 3600) {
    return x.multiply(y);
return x.multiply(y);
booleannegative(BigInteger n)
Checks whether n is negative.
return n.signum() < 0;
BigIntegernormalizarParaBigInteger(Number numero, RoundingMode modo)
normalizar Para Big Integer
BigInteger valor;
if (numero instanceof BigDecimal) {
    if (modo != null) {
        valor = ((BigDecimal) numero).divide(BigDecimal.ONE, modo).toBigIntegerExact();
    } else {
        valor = ((BigDecimal) numero).toBigIntegerExact();
} else if (numero instanceof Double) {
...
StringnumberToIpv4(BigInteger ipNumber)
number To Ipv
String ipString = "";
BigInteger a = new BigInteger("FF", 16);
for (int i = 0; i < 4; i++) {
    ipString = ipNumber.and(a).toString() + "." + ipString;
    ipNumber = ipNumber.shiftRight(8);
return ipString.substring(0, ipString.length() - 1);