Octal to binary program in c is a program to convert binary to octal in c.

What is the binary number?
A number expressed in base 2 represented in 0 and 1 are binary numbers.
What is the octal number?
A number expressed in base 8. The numbers from 0 to 7 are octal numbers.

How to convert octal to binary
We convert octal to octal to binary
1. Convert Octal to decimal
Octal to decimal conversion: write down the powers of eight start from right to left. Calculate the power of 8 for each digit. Write down the final value of each power of eight. Add the final values. This final result is our decimal number.

Octal to the decimal formula :
Decimal number = Add the power of 8 for each digit in an octal number.
2. Convert Decimal to binary
Decimal to binary conversion: we divide the decimal number by 2 continually which gives a reminder either 0 or 1 or until the final result is 0.

Decimal to the binary formula :
Simply divide a binary number by 2 and write down reminder o or 1 which is out a binary number.

Page Contents

## Octal to binary algorithm

1. Declare variable
2. Convert octal to decimal.
3. Convert Decimal to binary.
4. Print binary number.

## Octal to binary program in c

```#include<stdio.h>
#include<math.h>
int ConvertFromDecimalToOther(int,int);
int ConvertFromOctaltoDecimal(int);
int main()
{
int binary,decimal,octal;
printf("Enter Octal Number\n");
scanf("%d",&octal);
decimal=ConvertFromOctaltoDecimal(octal);
binary=ConvertFromDecimalToOther(decimal,2);
printf("Binary Number for given Octal Number %d is %d\n",octal,binary);
return(0);
}
int ConvertFromDecimalToOther(int decimal,int num)
{
int temp,final=0,i,j=1;
temp=decimal;
while(temp!=0)
{
i=temp%num;
final=final+(i*j);
temp=temp/num;
j=j*10;
}
return(final);
}

int ConvertFromOctaltoDecimal(int octal)
{
int dec=0,temp,i,inc=0;
temp=octal;
while(temp!=0)
{
i=temp%10;
dec=dec+(i*pow(8,inc));
temp=temp/10;
inc++;
}
return(dec);
}```

Output: 