• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 17, 2022 |850 Views

C++ Program to Convert Octal Number to Decimal and vice-versa

Description
Discussion

In this video, we will write a C++ program to Convert Octal Number to Decimal and vice-versa.

Decimal to Octal Conversion:

Algorithm:
Step 1: Remainder is stored when the number is divided by 8 in an array.
Step 2:Divide the number by 8 now
Step 3:Repeat the above two steps until the number is not equal to 0.
Step 4:Print the array in reverse order now.

Octal to Decimal Conversion:

Algorithm:
Step 1: The idea is to extract the digits of a given octal number starting from the rightmost digit and keep a variable decimal value.
Step 2: At the time of extracting digits from the octal number, multiply the digit with the proper base (Power of 8) and add it to the variable decimal value.
Step 3: In the end, the variable decimal value will store the required decimal number.

Octal to Decimal Conversion:
https://www.geeksforgeeks.org/program-octal-decimal-conversion/

Decimal to Octal Conversion:
https://www.geeksforgeeks.org/program-decimal-octal-conversion/