We would like to know how to parse and Format a Big Integer into Binary/octal/decimal/hexadecimal.
// w w w. j av a 2s .c om 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); bi = new BigInteger("1000", 8); System.out.println(s = bi.toString(8)); bi = new BigInteger("1023"); s = bi.toString(); System.out.println(s); bi = new BigInteger("3ff", 16); s = bi.toString(16); System.out.println(s); } }
The code above generates the following result.