Explore

Edit

Edit

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

Published on 10 Mar 2020

Program to convert a number from binary to octal using C, C++, Java and other programming languages is discussed here. Firstly let us look at an example to do this.

For example,

Consider the binary number 1111 which has to be converted to octal.
Divide the binary number into groups of three from right to left.

1111 can be grouped as 001 111
﻿
Now, find the octal number for each group.

Three-bit binary numbers from (000 to 111) have equal decimal and octal representations. Hence, the octal numbers for binary numbers in the range (000 to 111) are same as
that of the decimal numbers.

The octal number of 001 is 1 and 111 is 7.

The octal equivalent of 1111 is 17.


## Algorithm to convert a number from binary to octal

• Input the binary number.
• Divide the binary number into groups of three from right to left.
• Find the decimal equivalent of each group.
• The decimal equivalent of each group from left to right gives the equivalent octal number of the given binary number.

## Program to convert a number from binary to octal

C
C++
Java
Python 3

Output
Input- Enter a binary number:1111 Output- Octal Equivalent :17

Time complexity: O(n)

Recommended Programs