Java Utililty Methods BigInteger to

List of utility methods to do BigInteger to

Description

The list of methods to do BigInteger to are organized into topic(s).

Method

StringbigIntToIpV6(BigInteger argInt)
big Int To Ip V
StringBuilder str = new StringBuilder();
for (int i = 15; i >= 0; i--) {
    int shift = 8 * i;
    Integer n = 0xff;
    BigInteger num = argInt.shiftRight(shift).and(new BigInteger(n.toString()));
    int intNum = num.intValue();
    String s = Integer.toHexString(intNum);
    if (s.length() < 2) {
...
byte[]BigIntToPaddedByteArray(BigInteger bi, int length)
Converts a BigInt (What is stored in Hydra-keystore and what our version of SSSS is using...) to a padded byte-array.
byte[] biAsBytes = bi.toByteArray();
return paddedByteArray(biAsBytes, length);
voidbigIntToSortableBytes(BigInteger bigInt, int bigIntSize, byte[] result, int offset)
Encodes a BigInteger value such that unsigned byte order comparison is consistent with BigInteger#compareTo(BigInteger) .
byte[] bigIntBytes = bigInt.toByteArray();
byte[] fullBigIntBytes;
if (bigIntBytes.length < bigIntSize) {
    fullBigIntBytes = new byte[bigIntSize];
    System.arraycopy(bigIntBytes, 0, fullBigIntBytes, bigIntSize - bigIntBytes.length, bigIntBytes.length);
    if ((bigIntBytes[0] & 0x80) != 0) {
        Arrays.fill(fullBigIntBytes, 0, bigIntSize - bigIntBytes.length, (byte) 0xff);
} else if (bigIntBytes.length == bigIntSize) {
    fullBigIntBytes = bigIntBytes;
} else {
    throw new IllegalArgumentException(
            "BigInteger: " + bigInt + " requires more than " + bigIntSize + " bytes storage");
fullBigIntBytes[0] ^= 0x80;
System.arraycopy(fullBigIntBytes, 0, result, offset, bigIntSize);
assert sortableBytesToBigInt(result, offset, bigIntSize).equals(bigInt) : "bigInt=" + bigInt + " converted="
        + sortableBytesToBigInt(result, offset, bigIntSize);
StringbiToHex(BigInteger bi)
Turn a BigInteger into a hex string.
return bytesToHex(bi.toByteArray());
byte[]byteConvert32Bytes(BigInteger n)
byte Convert Bytes
byte tmpd[] = (byte[]) null;
if (n == null) {
    return null;
if (n.toByteArray().length == 33) {
    tmpd = new byte[32];
    System.arraycopy(n.toByteArray(), 1, tmpd, 0, 32);
} else if (n.toByteArray().length == 32) {
...
BigIntegerconcat(BigInteger left, BigInteger right)
concat
return concat(left, right, right.bitLength());
Stringconvert(BigInteger value, int base, boolean extra)
Convert value to a string in the given base.
if (base == 2) {
    if (extra)
        return value.toString(2) + "B";
    else
        return value.toString(2);
} else if (base == 10) {
    return value.toString();
} else if (base == 16) {
...
ListconvertAllElementsToLong(P bigIntegers)
convert All Elements To Long
if (bigIntegers == null) {
    return null;
try {
    ArrayList<Long> results = new ArrayList<Long>();
    for (BigInteger bigInteger : bigIntegers) {
        results.add(bigInteger.longValue());
    return results;
} catch (Exception e) {
    throw new RuntimeException(e);
InetAddressconvertBigIntegerIntoInetAddress(final BigInteger i)
convert Big Integer Into Inet Address
if (i.compareTo(BigInteger.ZERO) < 0) {
    throw new IllegalArgumentException(
            "BigInteger is negative, cannot convert into an IP address: " + i.toString());
} else {
    final byte[] bytes = i.toByteArray();
    if (bytes.length == 0) {
        return InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 });
    } else if (bytes.length <= 4) {
...
byte[]convertBigIntegerToNBytes(final BigInteger bigInteger, final int numBytes)
Utility method to convert BigInteger to n element byte array
if (bigInteger == null) {
    return null;
byte[] inputArray = bigInteger.toByteArray();
byte[] outputArray = new byte[numBytes];
if (bigInteger.compareTo(BigInteger.ZERO) < 0) {
    Arrays.fill(outputArray, (byte) -1);
} else {
...