Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Parsing and Formatting a Big Integer into Octal in Java
Firstly, take two BigInteger objects and set values.
BigInteger one, two;
one = new BigInteger("99");
Now, parse BigInteger object “two” into Octal.
two = new BigInteger("1100", 8);
String str = two.toString(8);
Above, we have used the following constructor. Here, radix is set as 8 for Octal. for both BigInteger constructor and toString() method.
BigInteger(String val, int radix)
This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.
The following is an example −
Example
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("99");
// parsing BigInteger object "two" into Octal
two = new BigInteger("1100", 8);
String str = two.toString(8);
System.out.println("Result (BigInteger) : " +one);
System.out.println("Result after parsing : " +str);
}
}
Output
Result (BigInteger) : 99 Result after parsing : 1100
Advertisements