Create BigInteger from byte array in Java
Description
The following code shows how to create BigInteger from byte array.
Example
/*from ww w. j av a2s.c om*/
import java.math.BigInteger;
public class Main {
public static void main(String[] argv) throws Exception {
// A negative value
byte[] bytes = new byte[] { (byte) 0xFF, 0x00, 0x00 }; // -65536
BigInteger bi = new BigInteger(bytes);
System.out.println(bi);
// A positive value
bytes = new byte[] { 0x1, 0x00, 0x00 }; // 65536
bi = new BigInteger(bytes);
System.out.println(bi);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »