# Octal To Binary Conversion | C Program

## Octal to binary conversion:-

The C program helps to convert octal number to binary number. In this program, the user is asked to insert an octal number and by using a loop or if-else statement, the user can convert an octal number to binary number. An integer variable is required to be used in the program.

Read Also: Program for Octal to Decimal Conversion ### Working:-

Step 1: Start

Step 2: Ask the user to enter an octal number as an input.

Step 3: Store the inserted number in the array octalnum.

Step 4: With the help of switch statement, evaluate every number of the octal number

Step 5: Print the equal binary value in a 3 digit number (Eg. 000)

Step 6: Do step 4 under the while loop.

Step 7: Stop ### Program to convert octal number to binary number:

```/*
* C Program to Convert Octal to Binary number
*/
#include<stdio.h>#include<conio.h>

#define MAX 1000

int main()
{
char octalnum[MAX];    //For initialize
long i = 0;    //taking user input of octalnum
printf("Insert an octal number: ");
scanf("%s", octalnum);
printf("Equivalent binary number: ");
while (octalnum[i])
{        //use switch case for multiple condition
switch (octalnum[i])
{
case '0':
printf("000"); break;
case '1':
printf("001"); break;
case '2':
printf("010"); break;
case '3':
printf("011"); break;
case '4':
printf("100"); break;
case '5':
printf("101"); break;
case '6':
printf("110"); break;
case '7':
printf("111"); break;
//for invalid case           default:
printf("\n Invalid octal digit %c ", octalnum[i]);
return 0;
}
i++;
}
return 0;
}```

### Output

```Insert an octal number: a
Equivalent binary value:
Invalid octal digit a
Insert an octal number: 160
Equivalent binary value: 001110000```