How to convert binary number to decimal number in C++ Program

CWC
0 Min Read

How to convert binary number to decimal number in C++ Program

#include
#include
#include 
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;
}
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version