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

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

The Octal numeral system uses the number 8 as its base (radix). As a base-8 numeral system, it consists of only eight numbers: 0,1,2,3,4,5,6 and 7.

The decimal numeral system is the most commonly used and the standard system in daily life. It uses the number 10 as its base (radix). Therefore, it has 10 symbols: The numbers from 0 to 9; namely 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

How to Convert Octal to Decimal

Step 1: Write down the Octal number.
Step 2: Starting with the least significant digit (LSB - the rightmost one), multiply the digit by the value of the position. Continue doing this until you reach the most significant digit (MSB - the leftmost one).
Step 3: Add the results and you will get the decimal equivalent of the given binary number.

Example: (123)8

Step 1: Write down (123)8 and determine the positions, namely the powers of 8 that the digit belongs to.
Step 2: Represent the number in terms of its positions.  (1* 82) + (2 * 81) + (3 * 80)
Step 3: (1 * 64) + (2 * 8) + (3 * 1) = 64 + 16 + 3 =83
Therefore,(123)8 = (83)10

C++ program to convert octal number to decimal


Output

Enter a Octal number: 123
123 in Octal = 83 in decimal

C++ Program to convert decimal number to octal


Output

Enter a decimal number: 83
83 in decimal = 123 in binary

Post a Comment

Thank you for vising

Previous Post Next Post