Java BigInteger Calculate getBytes(BigInteger bi, int minLen)

Here you can find the source of getBytes(BigInteger bi, int minLen)

Description

get Bytes

License

Apache License

Declaration

private static byte[] getBytes(BigInteger bi, int minLen) 

Method Source Code


//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;
    }
}

Related

  1. gcd(Iterable nums)
  2. gcdEuclides(BigInteger a, BigInteger b)
  3. gcdExtended(BigInteger p, BigInteger q)
  4. getAddressText(BigInteger address)
  5. getByteArrayFromBigIntegerArray(Object value)
  6. getBytes(BigInteger big, int bitlen)
  7. getBytesWithoutSign(BigInteger arg)
  8. getClearExpPipe(BigInteger M)
  9. getCreateLocalNextHopJobKey(Long vpnId, BigInteger dpnId, String prefix)