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

In this tutorial we are going to see what is Binary number, What is octal numbers, how to convert octal to binary, c program to convert octal to binary.

**What is binary number**

A number expressed in base 2 represented in 0 and 1 are binary numbers.

**What is octal numbers**

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

**Octal to decimal conversion** : write down the powers of eight start from right to left. Calculate 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 decimal formula : **

Decimal number = Add the power of 8 for each digits in octal number.

**Decimal to binary conversion** : we divide the decimal number by 2 continually which gives reminder either 0 or 1 or until final result is 0.

**Decimal to binary formula : **

Simply divide binary number by 2 and write down reminder o or 1 which is out binary number.

**Concept you need to know from c**

1. While loop in c

2. Assignment and arithmetic operator in c

3. Functions in c

**Octal to binary algorithm **

1. Start

2. Declare variable

3. Convert octal to decimal.

4. Next convert Decimal to binary.

5. print binary number.

6. End

## Octal to binary program in c

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#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:**

**Explanation:**

1. Write header files.

2. Write main function.

3. Write a function to convert octal to decimal

4. now convert decimal number to binary number.

5. Print binary number for given octal number.

## Leave a Reply