Convert octal number to decimal number in Java



To convert octal to decimal number, use the Integer.parseInt() method with radix 8. Here, the radix is for Octal i.e. 8.

Let’s say we have the following octal string.

String myOctal = "25";

To convert it to decimal, use the Integer.parseInt() method.

int val = Integer.parseInt(myOctal, 8);

The following is the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      String myOctal = "25";
      System.out.println("Octal = "+myOctal);
      int val = Integer.parseInt(myOctal, 8);
      System.out.println("Decimal = "+val);
   }
}

Output

Octal = 25
Decimal = 21
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements