Here you can find the source of getBytes(BigInteger bi, int minLen)
private static byte[] getBytes(BigInteger bi, int minLen)
//package com.java2s; //License from project: Apache License import java.math.BigInteger; import java.util.Arrays; public class Main { private static byte[] getBytes(BigInteger bi, int minLen) { byte[] ret = bi.toByteArray(); if (ret[0] == 0) { // remove leading 0 that makes num positive byte copy[] = new byte[ret.length - 1]; System.arraycopy(ret, 1, copy, 0, copy.length); ret = copy;/*from w w w .j a va 2 s . com*/ } // leading digits are dropped byte copy[] = new byte[minLen]; if (bi.compareTo(BigInteger.ZERO) < 0) { Arrays.fill(copy, (byte) 0xff); } System.arraycopy(ret, 0, copy, minLen - ret.length, ret.length); return copy; } }