C++ Binary to Decimal

#include<iostream>
using namespace std;
int main()
{
    int b = 1, c;
    unsigned long long int s = 0, a;

    cout << "Enter Binary Number : ";
    cin >> a;
    cout << endl;

    while(a != 0)
    {
        c = a%10;
        s = s + (c*b);
        a = a/10;
        b = b * 2;
    }

    cout << "Decimal Number :: " << s << endl;

    return 0;
}

Comments