Create BigInteger from binary string in Java
Description
The following code shows how to create BigInteger from binary string.
Example
//from w w w .j a v a2 s. c o m
import java.math.BigInteger;
import java.util.Arrays;
public class Main {
public static void main(String[] argv) throws Exception {
BigInteger bi = new BigInteger("100101000111111110000", 2);
byte[] bytes = bi.toByteArray();
System.out.println(Arrays.toString(bytes));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »