Parse Octal string to create BigInteger in Java


To parse the octal string to create BigInteger, use the following BigInteger constructor and set the radix as 8 for Octal −

BigInteger(String val, int radix)

This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.

In the below example, we have set the BigInteger and radix is set as 8.

BigInteger one, two;
one = new BigInteger("12");
two = new BigInteger("4373427", 8);

The following is the complete example −

Example

 Live Demo

import java.math.*;
public class Demo {
   public static void main(String[] args) {
      BigInteger one, two;
      one = new BigInteger("12");
      two = new BigInteger("4373427", 8);
      System.out.println("Result (BigInteger) : " +one);
      System.out.println("Result (Parsing Octal String) : " +two);
   }
}

Output

Result (BigInteger) : 12
Result (Parsing Octal String) : 1177367

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 29-Jun-2020

95 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements