Convert Binary to Decimal in C

Advertisements

Prev Tutorial Next Tutorial

Write a Program in C to Convert Binary to Decimal

In this types of program we takes a binary number as input and converts it into decimal number.

convert binary to decimal
  • Take a binary number as input.
  • Multiply each digits of the binary number starting from the last with the powers of 2 respectively.
  • Add all the multiplied digits.
  • Here total sum gives the decimal number.

Convert Binary to Decimal in C

#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr();
	long int bin_number, dec_number=0, i=1, rem;
	printf("Please Enter any Binary Number: ");
	scanf("%ld",&bin_number);
	while(bin_number!=0)
	{
		rem=bin_number%10;
		dec_number=dec_number+rem*i;
		i=i*2;
		bin_number=bin_number/10;
	}
	printf("Equivalent Decimal value: %ld",dec_number);
	getch();
}

Output

Please Enter any Binary Number: 11011
Equivalent Decimal value: 27 

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements