C Program to Convert Octal to Decimal

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

In this article, we are going to discuss the conversion of octal to decimal in C. The term "octal to decimal conversion" refers to the process of converting an octal number with an 8-base to a decimal number with a 10-base.

Octal Number System: Octal is a base-eight number system. There are eight different digits to work with, from 0 to 7. These eight digits make the octal system a base-eight system.

Decimal Number System: In the decimal system, we work with ten different digits, 0 to 9. These ten digits make the decimal system a base-ten system.

We need to write a program that takes an octal number as input and converts it to a decimal equivalent.
Example:

Introduction

The base number is used to convert octal to decimal in C, as it is for any other number conversion. To convert an octal number system to a decimal number system, multiply each octal digit by the power of 8, starting on the rightmost digit and multiplying it with 8 to the power zero then move left, for every next digit increase power of 8. Sum up all the products to get the decimal number.

Consider the diagram below to see how to convert octal to decimal.

Introduction to octal number

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Algorithm to Convert Octal to Decimal

The concept is to extract the digits of an octal number starting with the rightmost digit and store them in a variable called ans. Multiply the digit with the appropriate base (Power of 8) and add it to the variable ans when extracting digits from an octal number. The variable ans will ultimately hold the requisite decimal number.

Steps: Assume that num is the input octal number.

  1. Initialize x = 0, ans = 0.
  2. Repeat the following steps while num > 0.
    • Set -> y = num % 10, y will have last digit.
    • Remove last digit of number in num variable -> num = num / 10.
    • ans = ans + y * 8^x
    • updated vale of x varable by 1 till num > 0 -> x = x + 1
  3. Return ans.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Program to Convert Octal to Decimal in C

Output:

Explanation:

In OctalToDecimal function, While loop will traverse over the number and extract the digits from it then add the product of the digit and appropriate power of 8 to the ans. In the end, ans will have the converted decimal number which OctalToDecimal() returns.

Conclusion

  • We have discussed the algorithm of C program to convert octal to decimal.
  • We also have discussed how to convert octal to decimal numbers.
  • Octal number is a base-eight number system.
  • Decimal number is a base-ten number system.
  • If the Octal Number input is a char array, we must first convert it to integer form.