Here you can find the source of getUnsignedBytes(BigInteger number, int length)
Parameter | Description |
---|---|
number | The BigInteger. Must be >= 0. |
length | The maximum length. |
length
bytes of the given big integer, filled with zeros if necessary.
public static byte[] getUnsignedBytes(BigInteger number, int length)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { /**/*from w w w. j ava2 s .c o m*/ * Returns an unsigned byte[] representation of the given big integer. * * @param number * The BigInteger. Must be >= 0. * @param length * The maximum length. * @return The last <code>length</code> bytes of the given big integer, * filled with zeros if necessary. */ public static byte[] getUnsignedBytes(BigInteger number, int length) { byte[] value = number.toByteArray(); if (value.length > length + 1) { throw new IllegalArgumentException( "The given BigInteger does not fit into a byte array with the given length: " + value.length + " > " + length); } byte[] result = new byte[length]; int i = value.length == length + 1 ? 1 : 0; for (; i < value.length; i++) { result[i + length - value.length] = value[i]; } return result; } }