Format a Big Integer into Binary in Java
Description
The following code shows how to format a Big Integer into Binary.
Example
// w w w . j av a 2 s. com
import java.math.BigInteger;
public class Main {
public static void main(String[] argv) throws Exception {
BigInteger bi = new BigInteger("1023");
// Parse and format to binary
bi = new BigInteger("1111111111", 2);
String s = bi.toString(2);
System.out.println(s);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »