C++ Program to perform Binary to Decimal Conversion [DEVCPP/GCC]

PROGRAM

// Program to perform Binary to Decimal Conversion

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
        int i=0,digit;
        long bin;
        long dec=0;

        cout<<"ENTER BINARY NUMBER: ";
        cin>>bin;

        while(bin>0)
        {
                digit=bin%10;                  
                dec=dec+(pow(2,i)*digit);
                bin=bin/10;
                i++;
        }

        cout<<"DECIMAL EQUIVALENT: "<<dec;
        return 0;
}

OUTPUT

C++ Program to perform Binary to Decimal Conversion with output

Share this

Related Posts

FIND US ON FACEBOOK!