Here is given c program for binary to decimal conversion. But before let us see what is a Binary number is? A binary number is a number formed using only two digits i.e 1 or 0. A Decimal number is a number with base 10 which is in used very efficiently for manually calculations.Let us understand the conversion process through example.Suppose we have a binary number 1101 which is needed to be converted to decimal than its equivalent decimal number can be calculated as:
Multiplying 2 with last digit of binary number + Multiplying 21 with second last digit of binary number
and so on upto the number is…i.e
1101 is equivalent to = 2 * 1 + 21 * 0 + 22 * 1 + 23 * 1 = 13.
Hence 13 is decimal equivalent of binary number 1101.
ALSO CHECK: java program for binary to decimal conversion.
Program for binary to decimal conversion in c
clrscr(); // clearing the screen
printf("Enter the number in binary\n");
scanf("%d",&num); // Taking input binary number
n=num; // assingning the num value to n
rem=n%10; // Taking the last digit of binary number
d=rem*j; // j is a variable initialized to 1 which is 2^0
dec=dec+d; // dec is a variable used to store the decimal number after the calculation
n=n/10; // skipping the last digit and again repeating the loop for next iteration.
printf("The Decimal Number is\n");
printf("%d",dec); // output the decimal number.
getch(); // getting the char from keyboard to halt the program
Incoming terms: C program to convert binary number to decimal number.