Parse Octal string to create BigInteger in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Updated on 29-Jun-2020 05:48:05

Advertisements