Java BigInteger to toBytes(BigInteger bigInt, int expectedSize)

Here you can find the source of toBytes(BigInteger bigInt, int expectedSize)

Description

to Bytes

License

BSD License

Declaration

public static byte[] toBytes(BigInteger bigInt, int expectedSize) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.math.BigInteger;

public class Main {
    public static byte[] toBytes(BigInteger bigInt, int expectedSize) {
        byte[] tempArray = bigInt.toByteArray();
        byte[] resArray = new byte[expectedSize];
        if (tempArray.length > expectedSize) {
            System.arraycopy(tempArray, (tempArray.length - expectedSize),
                    resArray, 0, expectedSize);
            return resArray;
        } else {//from   ww  w  . ja  va  2s  . c  om
            return tempArray;
        }
    }
}

Related

  1. toBase_128(BigInteger val)
  2. toByteArray(BigInteger i)
  3. toByteArray(final BigInteger b)
  4. toByteArray(final BigInteger value, final int numBytes)
  5. toByteArrayUnsigned(BigInteger bi)
  6. toBytesUnsigned(final BigInteger bigInt)
  7. toDecimal(BigInteger value, byte[] buffer, int offset, int length, int itemLength, byte pos)
  8. toEvenLengthHex(BigInteger value)
  9. toFixedLenByteArray(BigInteger x, int resultByteLen)