In this article, we are going to learn how to convert an Octal number to an equivalent Decimal number. Here we are going to learn about two number systems one is octal and another is Decimal. Octal numbers are base 8 numbers. Decimal numbers are base 10 numbers and are represented in numbers from 0 to 9.
The Octal to Decimal equivalent number table is given below
Octal Number | Decimal Number |
0 | 0 |
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
7 | 7 |
C program to convert Octal to Decimal number
In this example, we take input octal numbers from the user and convert them decimal using the same logic as in the below code example.
#include <stdio.h>
#include <math.h>
int main()
{
int octNum;
int tmpOctNo;
int decNum;
int rem, place;
printf("Please enter an octal number: ");
scanf("%d",&octNum);
tmpOctNo = octNum;
decNum = 0;
place = 0;
while(tmpOctNo > 0)
{
rem = tmpOctNo % 10;
decNum += pow(8, place) * rem;
tmpOctNo =tmpOctNo/10;
place++;
}
printf("Decimal Equivalent to Octal number %d is %d\n", octNum,decNum);
return 0;
}
Output
Please enter an octal number: 12
Decimal Equivalent to Octal number 12 is 10
Please enter an octal number: 7
Decimal Equivalent to Octal number 7 is 7