Create BigInteger from byte array in Java


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 29-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements