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

StringgetQosFlowId(short tableId, BigInteger dpId, int lportTag)
get Qos Flow Id
return new StringBuffer().append(tableId).append(dpId).append(lportTag).toString();
StringgetRadixNumberInString(BigInteger integerNumber, int radix)
This method gets the required representation of any number according to the given radix or base.
return integerNumber.toString(radix);
BigIntegergetRandomBigInteger(int bits)
Creates a random BigInteger greater than 0 with the specified number of bits.
return new BigInteger(bits, new Random());
BigIntegergetRandomInteger(BigInteger n, Random rand)
Return a uniformly chosen integer between 0 and n-1.
BigInteger r;
int maxbits = n.bitLength();
do {
    r = new BigInteger(maxbits, rand);
} while (r.compareTo(n) >= 0);
return r;
intgetSize(BigInteger number)
Returns the number of bits in the two's-complement representation of the given number, including a sign bit only if number is less than zero.
int cmp = number.compareTo(BigInteger.ZERO);
if (cmp == 0) {
    return 1;
} else {
    int bitLength = number.bitLength();
    return (cmp > 0) ? bitLength : bitLength + 1;
StringgetValueWithUnit(BigInteger value, final int places)
Returns the given number as a string complete with unit (e.g., kilo, mega, etc.), to the specififed number of decimal places.
if (value == null)
    return null;
String s = "1";
for (int i = 0; i < places; i++)
    s += "0";
final BigInteger scale = new BigInteger(s);
value = value.multiply(scale);
int unit = 0;
...
StringgetVersionString(BigInteger versionNumber)
get Version String
StringBuilder versionStringBuilder = new StringBuilder();
BigInteger integerMask = BigInteger.valueOf(Integer.MAX_VALUE);
for (int i = 0; i < MAX_DIVISIONS; i++) {
    int division = (short) versionNumber.shiftRight((Integer.SIZE * (MAX_DIVISIONS - 1 - i)))
            .and(integerMask).intValue();
    if (versionStringBuilder.length() != 0) {
        versionStringBuilder.append(".");
    versionStringBuilder.append(division);
return versionStringBuilder.toString();
booleangreater(BigInteger i1, BigInteger i2)
greater
return i1.subtract(i2).signum() > 0;
StringhexEncode(BigInteger bigInteger)
Returns the BigInteger as a hex encoded string.
return hexEncode(bigInteger, null);
BigIntegerincrement(BigInteger integer)
Increments the given integer by one.
return add(integer == null ? BigInteger.ZERO : integer, BigInteger.ONE);