Java BigInteger Create toBigInteger(final byte[] bytes)

Here you can find the source of toBigInteger(final byte[] bytes)

Description

Converts a little endian byte array to a BigInteger.

License

Open Source License

Parameter

Parameter Description
bytes The bytes to convert.

Return

The resulting BigInteger.

Declaration

public static BigInteger toBigInteger(final byte[] bytes) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    /**//w  w  w . jav a 2  s  . c o  m
     * Converts a little endian byte array to a BigInteger.
     *
     * @param bytes The bytes to convert.
     * @return The resulting BigInteger.
     */
    public static BigInteger toBigInteger(final byte[] bytes) {
        final byte[] bigEndianBytes = new byte[bytes.length + 1];
        for (int i = 0; i < bytes.length; ++i) {
            bigEndianBytes[i + 1] = bytes[bytes.length - i - 1];
        }

        return new BigInteger(bigEndianBytes);
    }
}

Related

  1. hexToBigInteger(String hex)
  2. hexToBigInteger(String hex)
  3. toBigInteger(byte[] bytes)
  4. toBigInteger(final byte[] array, final int offset, final int length)
  5. toBigInteger(final byte[] buffer, final int offset, final int length)
  6. toBigInteger(final Integer i)
  7. toBigInteger(int arg)
  8. toBigInteger(int[] x, int bitsPerDigit)
  9. toBigInteger(List integerVector)