![]() |
The Java Developers Almanac 1.4 |
|
e130. Parsing and Formatting a Big Integer into Binary, Octal, and Hexadecimal BigInteger bi = new BigInteger("1023");
// Parse and format to binary
bi = new BigInteger("1111111111", 2); // 1023
String s = bi.toString(2); // 1111111111
// Parse and format to octal
bi = new BigInteger("1777", 8); // 1023
s = bi.toString(8); // 1777
// Parse and format to decimal
bi = new BigInteger("1023"); // 1023
s = bi.toString(); // 1023
// Parse and format to hexadecimal
bi = new BigInteger("3ff", 16); // 1023
s = bi.toString(16); // 3ff
// Parse and format to arbitrary radix <= Character.MAX_RADIX
int radix = 32;
bi = new BigInteger("vv", radix); // 1023
s = bi.toString(radix); // vv
e127. Operating with Big Decimal Values e128. Setting the Decimal Place of a Big Decimal Value e129. Performing Bitwise Operations with BigInteger e131. Parsing and Formatting a Byte Array into Binary, Octal, and Hexadecimal © 2002 Addison-Wesley. |