A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-program-to-convert-octal-to-decimal/ below:

Java Program to Convert Octal to Decimal

Java Program to Convert Octal to Decimal

Last Updated : 23 Jul, 2025

Octal numbers are numbers with 8 bases and use digits from 0-7. This system is a base 8 number system. The decimal numbers are the numbers with 10 as their base and use digits from 0-9 to represent the decimal number. They also require dots to represent decimal fractions.

We have to convert a number that is in the Octal Number System to the Decimal Number System. The base in an Octal Number is 8, which means that an Octal Number will have digits ranging from 0 to 7.

Basic Input/Output to Convert Octal To Decimal:

Input: 167 (Octal)
Output: (7 * 80) + (6 * 81) +(1 * 82)=119 (Decimal)

The diagram below explains how to convert an octal number (123) to an equivalent decimal value:

Methods to Convert Octal to Decimal

There are two main methods to convert Octal to Decimal in Java. They are:

1. Using Integer.parseInt() Method

To convert any string form to decimal, we can use type.parseType() method. For example, here we need to convert from octal to decimal, and the octal form is an integer, so we can use Integer.parseInt() to convert it.

Example: Java program for octal to decimal number conversion using Integer.parseInt() method.

Java
// Java program to convert
// octal number to decimal using
// Integer.parseInt()
public class Geeks
{
    public static void main(String args[])
    {
        // octal value
        String oct = "157";

        // octal to decimal using Integer.parseInt()
        int num = Integer.parseInt(oct, 8);

        System.out.println(
            "Decimal equivalent of Octal value of 157 is: "
            + num);
    }
}

Output
Decimal equivalent of Octal value of 157 is: 111

Complexity Analysis:

2. Custom Method to Convert Octal to Decimal

Algorithm:

Example: Java program for octal to decimal number conversion using custom method.

Java
// Java program to convert octal
// to decimal number using custom code
import java.lang.Math;

// Driver Class
public class Geeks
{
    // main function
    public static void main(String[] args)
    {
        int a = 167;

        // Initialize result variable to 0.
        int res = 0;

        // Take a copy of input
        int copy_a = a;

        for (int i = 0; copy_a > 0; i++) {

            // Take the last digit
            int temp = copy_a % 10;

            // Appropriate power on 8 suitable to
            // its position.
            double p = Math.pow(8, i);

            // Multiply the digits to the  into the Input
            // and
            //  then add it to result
            res += (temp * p);
            copy_a = copy_a / 10;
        }

        System.out.print("Decimal of Octal Number (" + a
                         + ") : " + res);
    }
}

Output
Decimal of Octal Number (167) : 119

Complexity Analysis:

Please refer to the article Program for Octal to Decimal Conversion for more information.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4