Binary to decimal conversion in C++ by R4R Team

Decimal number:
range : 0 to 9

Binary number :
range : 0 to 1

Binary to decimal conversion:
Example-
Binary number is 1000
Decimal number is 8
Binary number is 10111
Decimal number is 23

program:


#include< iostream>
#include< math.h>
int main() {
int n,num=0,i=0,sum=0;
cout<<"Enter Binary number"<< endl;
cin>>n;
while(n)
{
num=n%10;
num=num*pow(2,i++);
sum=sum+num;
n=n/10;
}
cout<<"It's Decimal is "<< sum;
}


output-

Enter Binary number
1010
It's Decimal is 10

Enter Binary number
101
It's Decimal is 5

-In this program, we take an input of number in binary form and find its decimal equivalent.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!