Here you can find the source of copy_into_byte_array(BigInteger bi, byte[] a)
Parameter | Description |
---|---|
bi | the source BigInteger |
a | the destination array |
public static void copy_into_byte_array(BigInteger bi, byte[] a)
//package com.java2s; // modify it under the terms of the GNU General Public License as import java.math.BigInteger; public class Main { /**/*ww w . j a v a 2 s . c om*/ * * Copy a BigInteger into a byte array. This is a bit more tricky * than just copying the result of {@link BigInteger#toByteArray}. * First, the argument array {@code a} might need some zero * padding and second, {@link BigInteger#toByteArray} might have a * leading zero that does not fit into {@code a}. * <P> * * Asserts that the BigInteger {@code bi}, with leading zeros * removed, fits into {@code a}. * * @param bi the source BigInteger * @param a the destination array */ public static void copy_into_byte_array(BigInteger bi, byte[] a) { byte[] bia = bi.toByteArray(); assert bia.length <= a.length || (bia.length == a.length + 1 && bia[0] == 0); for (int i = 0; i < a.length - bia.length; i++) a[i] = 0; System.arraycopy(bia, bia.length == a.length + 1 ? 1 : 0, a, bia.length == a.length + 1 ? 0 : a.length - bia.length, bia.length == a.length + 1 ? a.length : bia.length); return; } }