Java BigInteger to byteConvert32Bytes(BigInteger n)

Here you can find the source of byteConvert32Bytes(BigInteger n)

Description

byte Convert Bytes

License

Open Source License

Declaration

public static byte[] byteConvert32Bytes(BigInteger n) 

Method Source Code


//package com.java2s;
import java.math.BigInteger;

public class Main {

    public static byte[] byteConvert32Bytes(BigInteger n) {
        byte tmpd[] = (byte[]) null;
        if (n == null) {
            return null;
        }/*from  ww w  .j  av a2s.c  o  m*/

        if (n.toByteArray().length == 33) {
            tmpd = new byte[32];
            System.arraycopy(n.toByteArray(), 1, tmpd, 0, 32);
        } else if (n.toByteArray().length == 32) {
            tmpd = n.toByteArray();
        } else {
            tmpd = new byte[32];
            for (int i = 0; i < 32 - n.toByteArray().length; i++) {
                tmpd[i] = 0;
            }
            System.arraycopy(n.toByteArray(), 0, tmpd, 32 - n.toByteArray().length, n.toByteArray().length);
        }
        return tmpd;
    }
}

Related

  1. bigIntToHex(BigInteger big)
  2. bigIntToIpV6(BigInteger argInt)
  3. BigIntToPaddedByteArray(BigInteger bi, int length)
  4. bigIntToSortableBytes(BigInteger bigInt, int bigIntSize, byte[] result, int offset)
  5. biToHex(BigInteger bi)
  6. concat(BigInteger left, BigInteger right)
  7. convert(BigInteger value, int base, boolean extra)
  8. convertAllElementsToLong(P bigIntegers)
  9. convertBigIntegerIntoInetAddress(final BigInteger i)