Java BigInteger to bigIntegerToBytes(BigInteger b, int numBytes)

Here you can find the source of bigIntegerToBytes(BigInteger b, int numBytes)

Description

big Integer To Bytes

License

Apache License

Declaration

public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) 

Method Source Code

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

import java.math.BigInteger;

public class Main {
    public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) {
        if (b == null) {
            return null;
        }//w  ww  . j a va 2  s .co  m
        byte[] bytes = new byte[numBytes];
        byte[] biBytes = b.toByteArray();
        int start = (biBytes.length == numBytes + 1) ? 1 : 0;
        int length = Math.min(biBytes.length, numBytes);
        System.arraycopy(biBytes, start, bytes, numBytes - length, length);
        return bytes;
    }
}

Related

  1. bigIntegerToAddress(BigInteger ethereumAddress)
  2. bigIntegerToBase64(BigInteger value)
  3. bigIntegerToBitArray(BigInteger x, int length)
  4. BigIntegerToByteArrayWithoutSign(BigInteger value)
  5. bigIntegerToBytes(BigInteger b, int numBytes)
  6. bigIntegerToBytes(BigInteger b, int numBytes)
  7. bigIntegerToBytes(BigInteger b, int numBytes)
  8. bigIntegerToBytes(BigInteger integer)
  9. bigIntegerToBytes(BigInteger n, byte[] data, int[] offset)