C Programming
- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer
Conversion of octal to binary in C
We will learn C program to convert octal to binary in this article. We will take an octal number as input from user then convert it to equivalent binary number using C program.
We know that octal number is 8 based number where we can use the digits from 0 to 7 for writing any number. On the other hand, binary is 2 based number where we have to use only 0 and 1 to write any number. Here, we will use this concept of their base to convert a number from octal to binary. So, let’s go ahead with code.
See details about how to convert octal to binary mathematically.
C program to convert octal to binary
// C program to convert a number from octal to binary
#include <stdio.h>
#include <math.h>
int main(){
int oct, dec = 0, c = 0;
long bin = 0;
printf("Enter any octal number here to convert : ");
scanf("%d", &oct);
while(oct != 0){
dec = dec + (oct % 10) * pow(8, c);
c++;
oct /= 10;
}
c = 1;
while(dec != 0){
bin = bin + (dec % 2) * c;
dec /= 2;
c *= 10;
}
printf("\nBinary number is = %ld\n", bin);
return 0;
}
Output of octal to binary conversion program:

Octal to binary conversion using function in C
// Octal to binary using function in C
#include <stdio.h>
#include <math.h>
long oct_to_bin(int oct_num);
int main(){
int oct;
printf("Enter the octal number to convert : ");
scanf("%d", &oct);
printf("\nBinary number is = %ld\n", oct_to_bin(oct));
return 0;
}
long oct_to_bin(int octal_num){
int decimal_num = 0, k = 0;
long binary_num = 0;
while(octal_num != 0){
decimal_num = decimal_num + (octal_num % 10) * pow(8, k);
k++;
octal_num /= 10;
}
k = 1;
while (decimal_num != 0){
binary_num = binary_num + (decimal_num % 2) * k;
decimal_num /= 2;
k *= 10;
}
return binary_num;
}
See the output of this program
Enter the octal number to convert : 56
Binary number is = 101110
Previous page:Â Binary to octal
Next page:Â Add using pointers
Recommended for you: