C Program to Convert Binary Number to Decimal
C Program to Convert Binary Number to Decimal
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
#include <stdio.h>
void main()
{
int num,rem,bin_val, dec_val = 0, base = 1;
printf("Enter a binary number(1s and 0s) \n");
scanf("%d", &num);
bin_val = num;
while (num > 0)
{
rem = num % 10;
dec_val = dec_val + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("The Binary number is = %d \n", bin_val);
printf("Decimal equivalent is = %d \n", dec_val);
}