List of utility methods to do BigInteger Calculate
String | int2zpBin(BigInteger num, int len) intzp Bin final String zeroPadding = rep('0', len); final String numString = num.toString(2); return (zeroPadding.substring(numString.length()) + numString); |
String | integerToString(BigInteger value) integer To String StringBuilder s = new StringBuilder(); while (value.bitLength() > 0) { BigInteger[] result = value.divideAndRemainder(BigInteger.valueOf(62)); value = result[0]; char c = intToChar(result[1].intValue()); s.insert(0, c); return s.toString(); ... |
int | intValue(BigInteger bi) Converts a BigInteger to an integer, if the BigInteger is in the correct range. if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0) throw new IllegalArgumentException("BigInteger [" + bi + "] is too small to convert to int."); if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0) throw new IllegalArgumentException("BigInteger [" + bi + "] is too big to convert to int."); return bi.intValue(); |
int | intValueExact(BigInteger bigint) int Value Exact if (bigint == null || bigint.bitLength() > 31) { throw new ArithmeticException(); return bigint.intValue(); |
BigInteger | jsonBigInteger(JsonValue value) json Big Integer if (value == null || value.getValueType() == JsonValue.ValueType.NULL) return null; if (value.getValueType() == JsonValue.ValueType.NUMBER && (value instanceof JsonNumber)) return ((JsonNumber) value).bigIntegerValue(); if (value.getValueType() == JsonValue.ValueType.STRING && (value instanceof JsonString)) { try { return new BigInteger(((JsonString) value).getString()); } catch (NumberFormatException ex) { ... |
int | length(BigInteger bi) length int length = 0; while (bi.compareTo(BigInteger.ZERO) > 0) { bi = bi.divide(BigInteger.TEN); length++; return length; |
BigInteger | listToBigInteger(List Transforms a List of Integer s representing non-zero bits into a BigInteger of the represented value. if (list == null || list.isEmpty()) { return BigInteger.ZERO; list.sort((i1, i2) -> i1 > i2 ? 1 : -1); int max = list.get(list.size() - 1); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < max; ++i) { buffer.append('0'); ... |
int | log2(BigInteger x) log return x.bitLength() - 1;
|
BigInteger | maskBits(BigInteger value, int bits) mask Bits BigInteger mask = BigInteger.ONE.shiftLeft(bits).subtract(BigInteger.ONE);
return value.and(mask);
|
BigInteger | min(BigInteger a, BigInteger b) Since Math.max() doesn't handle BigInteger if (a == null) return b; if (b == null) return a; int c = a.compareTo(b); return c > 0 ? b : a; |