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
Convert binary to decimal program in C
In this C programming guide we will see some C program to convert a binary number to its equivalent decimal number.
We know that binary number consists of only two digits 0 and 1 where decimal number consists of any number of digits from 0 to 9. In this program we will take the input from user which will be the binary number. Then we will convert it to the equivalent decimal number using C program. You can do this program in different way. Let’s see the program bellow;
If you want to know how to convert a binary number to decimal number mathematically then see this binary to decimal number conversion guide.
C program to convert binary to decimal
// c program to convert binary to decimal
#include <stdio.h>
#include <math.h>
int main(){
int deNum = 0, rem, tempNum = 0;
long biNum;
printf("Enter the binary number here : ");
scanf("%ld", &biNum);
while(biNum != 0){
rem = biNum % 10;
biNum /= 10;
deNum = deNum + rem * pow(2, tempNum);
tempNum++;
}
printf("Decimal equivalence is = %d", deNum);
return 0;
}
Output of this binary to decimal program :

Convert binary to decimal using function in C
// convert binary to decimal using function in C
#include <stdio.h>
#include <math.h>
int convertBtoD(long bNum);
int main(){
long b;
printf("Enter any binary number to convert : ");
scanf("%ld", &b);
int d = convertBtoD(b);
printf("\nDecimal equivalence is = %d\n", d);
return 0;
}
int convertBtoD(long bNum){
int dNum = 0, tNum = 0, rem;
while (bNum!=0){
rem = bNum % 10;
bNum = bNum / 10;
dNum = dNum + rem*pow(2,tNum);
tNum++;
}
return dNum;
}
Output of this binary to decimal program
Enter any binary number to convert : 1011001
Decimal equivalence is = 89
Previous page: Sum of natural numbers
Next page: Decimal to octal by C
Recommended for you: