C++ Program For Octal To Decimal Conversion Last Updated : 03 Jul, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an octal number as input, we need to write a program to convert the given octal number into an equivalent decimal number. Examples: Input : 67Output: 55 Input : 512Output: 330 Input : 123Output: 83 1. Simple ApproachThe idea is to extract the digits of a given octal number starting from the rightmost 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. In the end, the variable dec_value will store the required decimal number.Example: If the octal number is 67. dec_value = 6*(8^1) + 7*(8^0) = 55The below diagram explains how to convert an octal number (123) to an equivalent decimal value: Below is the implementation of the above idea. C++ // C++ program to convert octal // to decimal #include <iostream> using namespace std; // Function to convert octal // to decimal int octalToDecimal(int n) { int num = n; int dec_value = 0; // Initializing base value to 1, // i.e 8^0 int base = 1; int temp = num; while (temp) { // Extracting last digit int last_digit = temp % 10; temp = temp / 10; // Multiplying last digit with // appropriate base value and adding // it to dec_value dec_value += last_digit * base; base = base * 8; } return dec_value; } // Driver code int main() { int num = 67; cout << octalToDecimal(num) << endl; } Output55 The complexity of the above methodTime complexity: O(logN) where N is the given number Auxiliary space: O(1) 2. Using Predefined stoi() FunctionBelow is the C++ program for Octal to Decimal Conversion: C++ // C++ program to convert octal // to decimal #include <iostream> using namespace std; int OctToDec(string n) { return stoi(n, 0, 8); } // Driver code int main() { string n = "67"; cout << OctToDec(n); return 0; } // This code is contributed by phasing17 Output55Please refer complete article on Program for Octal to Decimal Conversion for more details! Comment More infoAdvertise with us Next Article C++ Program For Octal To Decimal Conversion K kartik Follow Improve Article Tags : C++ Programs C++ C++ Conversion Programs Practice Tags : CPP Similar Reads C++ Program For Decimal To Octal Conversion The octal numbers are a base 8 number system that uses digits from 0-7 and the decimal numbers are a base 10 numbers system that uses 10 digits from 0-9 to represent any numeric value. In this article, we will learn how to write a C++ program to convert a given decimal number into an equivalent octa 2 min read C++ Program For Hexadecimal To Decimal Conversion The hexadecimal numbers are base 16 numbers that use 16 symbols {0, 1, 2, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} to represent all digits. Here, (A, B, C, D, E, F) represents (10, 11, 12, 13, 14, 15). Decimal numbers are base 10 numbers with 10 symbols to represent all digits. In this article, we will l 3 min read C++ Program For Decimal To Hexadecimal Conversion In this article, we will learn to write a C++ program to convert a decimal number into an equivalent hexadecimal number. i.e. convert the number with base value 10 to base value 16. In the decimal system, we use ten digits (0 to 9) to represent a number, while in the hexadecimal system, we use sixte 3 min read C++ Program For Binary To Decimal Conversion The binary number system uses only two digits 0 and 1 to represent an integer and the Decimal number system uses ten digits 0 to 9 to represent a number. In this article, we will discuss the program for Binary to Decimal conversion in C++. Algorithm to Convert Binary Numbers to DecimalInitialize a v 4 min read C++ Program For Decimal To Binary Conversion Binary Numbers uses only 0 and 1 (base-2), while Decimal Number uses 0 to 9 (base-10). In this article, we will learn to implement a C++ program to convert Decimal numbers to Binary Numbers. The below diagram shows an example of converting the decimal number 17 to an equivalent binary number. Recomm 3 min read Like