Search This Blog

Program to Convert Binary to Decimal - Binary to Decimal Converter Program

This is a c program to convert a binary number to decimal number. The input (binary number) should contain only zeros and ones. Binary number system represents numbers using only two digits; 0 and 1. The following is a binary to decimal converter program in C.


#include<stdio.h> #include<string.h> int BinToDec(int bin) { int rem,dec=0,base=1; int num; num=bin; while(num>0)    {    rem = num % 10;    dec = dec + rem * base;    num = num / 10 ;    base = base * 2;    } return dec; } void main() { int inputnum; printf("\nEnter the binary number\n"); scanf("%d",&inputnum); printf("Corresponding decimal number is: %d",BinToDec(inputnum)); }

No comments: