C Programming Code Examples C > Conversions Code Examples C Program to Convert the given Binary Number into Decimal C Program to Convert the given Binary Number into Decimal - Take a binary number and store it in the variable j. - Initialize the variable decimal_val to zero and variable base to 1. - Obtain the remainder and quotient of the binary number. Store the remainder in the variable rem and override the variable j with quotient. - Multiply rem with variable base. Increment the variable decimal_val with this new value. - Increment the variable base by 2. - Repeat the steps 3, 4 and 5 with the quotient obtained until quotient becomes zero. - Print the variable decimal_val as output. #include <stdio.h> void main() { int j, binary_val, decimal_val = 0, base = 1, rem; printf("Enter a binary number(1s and 0s) \n"); scanf("%d", &j); /* maximum five digits */ binary_val = j; while (j > 0) { rem = j % 10; decimal_val = decimal_val + rem * base; j = j / 10 ; base = base * 2; } printf("The Binary number is = %d \n", binary_val); printf("Its decimal equivalent is = %d \n", decimal_val); }