16 C Program to Convert Octal to Binary
Posted by Superadmin on December 22 2015 03:20:34
This C Program Converts the given Octal to Binary. Octal is a numbering system that uses eight digits, 0 to 7, arranged in a series of columns to represent all numerical quantities. Each column or place value has a weighted value of 1, 8, 64, 512, and so on, ranging from right to left. Binary number is a number that can be represented using only two numeric symbols – 0 and 1. A number in base 2.
Here is source code of the C program to Convert Octal to Binary. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Convert Octal to Binary
*/
#include <stdio.h>
#define MAX 1000

int main()
{
char octalnum[MAX];
long i = 0;

printf("Enter any octal number: ");
scanf("%s", octalnum);
printf("Equivalent binary value: ");
while (octalnum[i])
{
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;
default:
printf("\n Invalid octal digit %c ", octalnum[i]);
return 0;
}
i++;
}
return 0;
}



Output:
$ cc pgm2.c
$ a.out
Enter any octal number: a
Equivalent binary value:
Invalid octal digit a

$ a.out
Enter any octal number: 160
Equivalent binary value: 001110000