Explore
Placement Prep

Edit

Edit

# Convert a number from octal to binary in C, C++, Java and Python | FACE Prep

Published on 09 Mar 2020

Program to convert a number from octal to binary is discussed here. Firstly, the given octal number is converted to a decimal number. Then, the decimal number is converted to binary.

For example, consider the octal number 17 which has to be converted to binary.

The decimal equivalent of the octal number 17 is calculated as follows

7 * 8^0 = 7
1 * 8^1 = 8

Decimal equivalent : 15 (8 + 7)

Now, this 15 is converted to binary

15 / 2 = 7 , rem = 1
7 / 2 = 3 , rem = 1
3 / 2 = 1 , rem = 1
1 / 2 = 0 , rem = 1

Binary Equivalent : 1111


## Algorithm to convert a number from octal to binary

Firstly, convert the number from octal to decimal.

• Input the octal number.
• Count the total number of digits in the given number.
• Assume that the number has n digits.
• Multiply each digit in the number with 8^(n-1), when the digit is in the nth position.
• Perform addition of all the digits after multiplication.
• The added sum gives the decimal equivalent of the octal number.

Then, convert the decimal number to binary,

• Divide the number by 2.
• Note the remainder during each division.
• Continue to divide until the number becomes 0.
• The Binary equivalent will be the reverse of the remainder.

## Program to convert a number from octal to binary

C
C++
Java
Python 3

Output
Input- Enter an octal number:67 Output- Binary Equivalent :110111

Time complexity:O(n)

Recommended Programs