codescracker


c

C Program to Convert Binary to Decimal



« Previous Program Next Program »


Binary to Decimal Conversion in C

To convert binary number to decimal number in C programming, you have to ask to the user to enter the binary number to convert it into decimal number and display the equivalent decimal value on the output screen as shown in the following program.

C Programming Code to Convert Binary to Decimal

Following C program ask to the user to enter any number in binary to convert it into decimal form, then display the result on the screen :

/* C Program - Binary to Decimal Conversion */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	long int binnum, decnum=0, i=1, rem;
	printf("Enter any binary number : ");
	scanf("%ld",&binnum);
	while(binnum!=0)
	{
		rem=binnum%10;
		decnum=decnum+rem*i;
		i=i*2;
		binnum=binnum/10;
	}
	printf("Equivalent decimal value = %ld",decnum);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program convert number from binary to decimal

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test