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

inttoInt(BigInteger number)
to Int
return number.intValue();
int[]toInt(int length, BigInteger bi)
to Int
byte[] ba = bi.toByteArray();
int[] ia = new int[length];
for (int j = ba.length - 1; j >= 0; j--) {
    int changeByte = ((ba.length - 1 - j) % 4);
    int jj = length - 1 - (ba.length - 1 - j) / 4;
    ia[jj] |= (ba[j] & 0xff) << (changeByte * 8);
return ia;
...
int[]toIntArray(BigInteger[] input)
Converts a BigInteger array into an integer array
int[] result = new int[input.length];
for (int i = 0; i < input.length; i++) {
    result[i] = input[i].intValue();
return result;
IntegertoInteger(BigInteger bi)
Converts a BigInteger to an integer, if the BigInteger is in the correct range.
if (bi == null)
    return null;
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();
IntegertoInteger(BigInteger integer)
to Integer
if (integer == null)
    return null;
return new Integer(integer.intValue());
byte[]toIntegerBytes(final BigInteger bigInt)
to Integer Bytes
int bitlen = bigInt.bitLength();
bitlen = bitlen + 7 >> 3 << 3;
final byte[] bigBytes = bigInt.toByteArray();
if (bigInt.bitLength() % 8 != 0 && bigInt.bitLength() / 8 + 1 == bitlen / 8)
    return bigBytes;
int startSrc = 0;
int len = bigBytes.length;
if (bigInt.bitLength() % 8 == 0) {
...
byte[]toMinimalByteArray(BigInteger value)
Return the value of big as a byte array.
byte[] valBytes = value.toByteArray();
if ((valBytes.length == 1) || (value.bitLength() & 0x07) != 0) {
    return valBytes;
byte[] result = new byte[value.bitLength() >> 3];
System.arraycopy(valBytes, 1, result, 0, result.length);
return result;
ObjecttoObject(BigInteger x)
to Object
if (x.compareTo(MAXINT) > 0 || x.compareTo(MININT) < 0) {
    return x;
} else {
    return Integer.valueOf(x.intValue());
byte[]toPaddedBytes(BigInteger bi, int length)
to Padded Bytes
byte[] biBytes = bi.toByteArray();
int diff = length - biBytes.length;
if (diff < 0)
    throw new NumberFormatException("BigInteger value is bigger than requested " + length + " bytes");
byte[] out = new byte[length];
System.arraycopy(biBytes, 0, out, diff, biBytes.length);
return out;
PushbackReadertoPushbackReader(BigInteger x)
to Pushback Reader
byte[] bytes = x.abs().toByteArray();
final int startB = (x.signum() < 0 ? '-' : -1); 
InputStream in = new ByteArrayInputStream(bytes) {
    public int read() {
        int c;
        if (this.b == -1) {
            this.b = super.read();
            if (this.b == -1) {
...