Java BigInteger Calculate renderBigInteger(final BigInteger bint)

Here you can find the source of renderBigInteger(final BigInteger bint)

Description

Return an 8 byte array from a BigInteger value.

License

Open Source License

Parameter

Parameter Description
bint the big integer object to render

Return

an 8 byte array representing the big integer.

Declaration

public static byte[] renderBigInteger(final BigInteger bint) 

Method Source Code

//package com.java2s;
/*//from  w  ww  .  j a v  a 2 s.co m
 * Copyright (c) 2014 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial API and implementation
 */

import java.math.BigInteger;

public class Main {
    /**
     * Return an 8 byte array from a BigInteger value.
     * 
     * Only 8 bytes will be supported, enough for a U64 value of over 18 
     * quintillion.
     * 
     * @param bint the big integer object to render
     * 
     * @return an 8 byte array representing the big integer.
     */
    public static byte[] renderBigInteger(final BigInteger bint) {
        final byte[] retval = new byte[8];
        byte[] arry = bint.toByteArray();

        if (arry.length > retval.length)
            System.arraycopy(arry, arry.length - retval.length, retval, 0, retval.length);
        else if (arry.length < retval.length)
            System.arraycopy(arry, 0, retval, retval.length - arry.length, arry.length);
        else
            System.arraycopy(arry, 0, retval, 0, retval.length);

        return retval;
    }
}

Related

  1. parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative)
  2. parseScaledNonNegativeBigInteger(String str)
  3. product(final BigInteger min, final BigInteger max)
  4. randomFromZn(BigInteger n, Random rand)
  5. removeDuplicates(final BigInteger... values)
  6. retrieveBigInteger(final byte[] buf, final int offset)
  7. rightshift(byte b1, BigInteger b2)
  8. saveKey(File destDir, String fileName, BigInteger modulus, BigInteger publicExponent)
  9. saveToFile(String fileName, BigInteger mod, BigInteger exp)