codescracker


c++

C++ Program to Convert Binary to Decimal



« Previous Program Next Program »


Binary to Decimal in C++

To convert binary to decimal in C++ Programming, you have to ask to the user to enter any number in binary to convert it into decimal, then display the equivalent decimal value on the output screen as shown here 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 */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	long int binnum, decnum=0, i=1, rem;
	cout<<"Enter any binary number : ";
	cin>>binnum;
	while(binnum!=0)
	{
		rem=binnum%10;
		decnum=decnum+rem*i;
		i=i*2;
		binnum=binnum/10;
	}
	cout<<"Equivalent decimal value = "<<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 Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test