Binary to Decimal conversion

Q. Write a C++ program to convert binary number to decimal number.

Answer:

Following program is converting a binary number to decimal number.

#include<iostream>
using namespace std;
int main()
{
        long int binnum, decinum=0, i=1, rem;
        cout<<"\n Enter Binary Number : ";
        cin>>binnum;
        while(binnum!=0)
        {
                rem=binnum%10;
                decinum=decinum+rem*i;
                i=i*2;
                binnum=binnum/10;
        }
        cout<<"\n Conversion of Binary Number to Decimal Number : "<<decinum;
        return 0;
}


Output:

binary to decimal