Java BigInteger to BigIntegerToEightBytes(BigInteger value)

Here you can find the source of BigIntegerToEightBytes(BigInteger value)

Description

This function converts big integer to eight bytes.

License

Open Source License

Parameter

Parameter Description
value BigInteger type

Exception

Parameter Description
Exception Exception

Return

value byte type

Declaration

public static final byte[] BigIntegerToEightBytes(BigInteger value) throws Exception 

Method Source Code


//package com.java2s;
/*//from  ww  w. ja v a2 s .  c o m
 * Copyright (c) 2016 Tata Consultancy Services and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.math.BigInteger;

public class Main {
    /**
     * This function converts big integer to eight bytes.
     * 
     * @param value
     *            BigInteger type
     * @return value byte type
     * @throws Exception
     *             Exception
     */
    public static final byte[] BigIntegerToEightBytes(BigInteger value) throws Exception {
        byte[] result = new byte[8];
        byte[] tmp = value.toByteArray();
        if (tmp.length > 8) {
            System.arraycopy(tmp, tmp.length - 8, result, 0, 8);
        } else {
            System.arraycopy(tmp, 0, result, 8 - tmp.length, tmp.length);
        }
        return result;
    }
}

Related

  1. bigIntegerToBytes(BigInteger b, int numBytes)
  2. bigIntegerToBytes(BigInteger integer)
  3. bigIntegerToBytes(BigInteger n, byte[] data, int[] offset)
  4. bigIntegerToBytes(final BigInteger bigInteger)
  5. bigIntegerToDigits(BigInteger n)
  6. bigIntegerToHex(final BigInteger bigInteger)
  7. bigIntegerToList(BigInteger number)
  8. bigIntegerToString(final BigInteger value)
  9. bigIntegerToUnsignedByteArray(BigInteger a, int len)