Given an octal number as input, we need to write a program to convert the given octal number into equivalent decimal number.
Input : 67 Output : 55 Input : 512 Output : 330 Input: 123 Output: 83
The idea is to extract the digits of given octal number starting from right most digit and keep a variable dec_value. 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 dec_value. At the end, the variable dec_value will store the required decimal number.
If the octal number is 67.
dec_value = 6*(8^1) + 7*(8^0) = 55
Below diagram explains how to convert octal number ( 123 ) to equivalent decimal value:
Below is the implementation of above idea.
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Program for decimal to octal conversion
- Decimal to octal conversion with minimum use of arithmetic operators
- Program for Binary To Decimal Conversion
- Program for Decimal to Binary Conversion
- Check if Decimal representation of an Octal number is divisible by 7
- Decimal to binary conversion without using arithmetic operators
- Program to Convert Hexadecimal to Octal
- Program to Convert Octal Number to Binary Number
- Program for hexadecimal to decimal
- Convert a binary number to octal
- Type Conversion in Python
- Flip-flop types and their Conversion
- StringStream in C++ for Decimal to Hexadecimal and back
- Decimal to binary number using recursion
- Decimal representation of given binary string is divisible by 10 or not