# Octal to Binary Conversion

“** Octal to Binary Conversion**” is one of the classic programming problem exercise for beginners. Here, we are given an octal number, entered by user and our task is to write a program to convert the given octal number to its equivalent binary number.

*Example:*

Octal = 65 Binary = 110101 Octal = 78 Binary = 11110000

The steps for octal to binary conversion are as follows:

- Scan the octal number from left to right.
- Convert each digit of octal number into corresponding 3-digit binary number.
- Combine all the 3-digit binary number to get the result.
- Truncate the front 0s of the binary number, if exist.
- Print the result.

**C++ Program for octal to binary conversion is as follows:**

```
/* C++ Program to Convert Octal Number to Binary Number */
#include<bits/stdc++.h>
using namespace std;
int main()
{
/* Scan the Octal Number */
int Octal;
cout<<"Enter the Octal Number: ";
cin>>Octal;
/* Converting Octal to Binary*/
string Binary;
int temp = Octal;
while(temp != 0)
{
int remainder = temp % 10;
string val;
/* Binary equivalent of each digit */
switch(remainder) {
case 0: val = "000";
break;
case 1: val = "001";
break;
case 2: val = "010";
break;
case 3: val = "011";
break;
case 4: val = "100";
break;
case 5: val = "101";
break;
case 6: val = "110";
break;
case 7: val = "111";
break;
case 8: val = "1000";
break;
case 9: val = "1001";
break;
}
Binary = val + Binary ;
temp = temp / 10;
}
/*Deleting the extra zeros from front*/
while(Binary[0]!='1')
{
Binary.erase(Binary.begin()+0);
}
/*Printing the result */
cout<<"The Binary of "<<Octal<<" is "<<Binary;
}
```

Enter the Octal Number: 78 The Binary of 78 is 1111000OUTPUT:

**Related Posts:**

- Program to convert octal number to decimal number.
- Program to convert octal number to hexadecimal number.
- Program to convert decimal number to binary number.
- Program to convert decimal number to octal number.
- Program to convert decimal number to hexadecimal number.
- Program to convert hexadecimal number to binary number.
- Program to convert hexadecimal number to octal number.
- Program to convert hexadecimal number to decimal number.
- Program to convert binary number to octal number.
- Program to convert binary number to decimal number.
- Program to convert binary number to hexadecimal number.
- Program to find Power of the Number.
- Program to find Quotient and Remainder.
- Program to find largest amongst three numbers.
- Program to find factorial of a number.
- Program to find GCD of two numbers.
- Program to find LCM of two numbers.
- Program to check whether entered number is odd or even.
- Program to check whether entered number is prime number or not.