Write a C++ program to convert a given Binary number to Decimal number. 

Program Code:
#include<iostream>
using namespace std;
int main()
{

int binary, deci = 0, i = 1, rem;
cout<<"Enter any binary number : ";
cin>>binary;
cout<<endl;
while(binary != 0)
{
rem = binary % 10;
deci = deci + rem * i;
i = i * 2;
binary = binary / 10;
}
cout<<"Equivalent decimal value = "<<deci;
return 0;

The program output is tested on www.jdoodle.com
Output:
Enter any binary number : 1111001
Equivalent decimal value = 121


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: