Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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
Updated on: 2020-06-29T05:28:41+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements