List of utility methods to do BigInteger Calculate
String | getQosFlowId(short tableId, BigInteger dpId, int lportTag) get Qos Flow Id return new StringBuffer().append(tableId).append(dpId).append(lportTag).toString(); |
String | getRadixNumberInString(BigInteger integerNumber, int radix) This method gets the required representation of any number according to the given radix or base. return integerNumber.toString(radix);
|
BigInteger | getRandomBigInteger(int bits) Creates a random BigInteger greater than 0 with the specified number of bits. return new BigInteger(bits, new Random()); |
BigInteger | getRandomInteger(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; |
int | getSize(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; |
String | getValueWithUnit(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; ... |
String | getVersionString(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(); |
boolean | greater(BigInteger i1, BigInteger i2) greater return i1.subtract(i2).signum() > 0;
|
String | hexEncode(BigInteger bigInteger) Returns the BigInteger as a hex encoded string. return hexEncode(bigInteger, null);
|
BigInteger | increment(BigInteger integer) Increments the given integer by one. return add(integer == null ? BigInteger.ZERO : integer, BigInteger.ONE);
|