Create BigInteger from byte array in Java

Java 8Object Oriented ProgrammingProgramming

BigInteger class provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

Let’s say the following is our byte array −

byte[] arr = new byte[] { 0x1, 0x00, 0x00 };

We will now convert them to BigInteger −

BigInteger bInteger = new BigInteger(arr);

The following is an example that creates BigInteger from a byte array in Java.

Example

 Live Demo

import java.math.BigInteger;
public class Demo {
   public static void main(String[] argv) throws Exception {
      byte[] arr = new byte[] { 0x1, 0x00, 0x00 };
      BigInteger bInteger = new BigInteger(arr);
      System.out.println(bInteger);
   }
}

Output

65536
raja
Published on 20-Dec-2018 05:58:12
Advertisements