Convert Binary to Decimal in C++

Here you will figure out how to change over parallel to decimal in C++.

We can change over a parallel number into decimal in following manner.

Increase every digit from right to left by intensity of 2. Here the intensity of 2 will be the situation of the digit beginning from 0.

Presently add every one of the qualities to acquire decimal number.

#include<iostream>
#include<math.h>
 
using namespace std;
 
int main()
{
	unsigned long i,n,num=0,d;
	cout<<"Enter any Binary number:";
	cin>>n;
	cout<<"\nThe Decimal conversion of "<<n<<" is ";
	
	for(i=0;n!=0;++i)
	{
	d=n%10;
	num=(d)*(pow(2,i))+num;
	n=n/10;
	}
 
	cout<<num;
	return 0;
}

Output

Enter any Binary number:111
The Decimal conversion of 111 is 7

Leave a Comment

error: Alert: Content is protected!!