Thursday, September 29, 2016

Binary To Decimal Conversion

Program To Convert Binary Number To Decimal:


#include<iostream>
#include<math.h> //for power function
using namespace std;
main()
{
    int binary,decimal=0,i=0,remainder;
    cout<<"\nEnter The Binary Number ";
    cin>>binary;
    while(binary!=0)
    {
        remainder=binary%10; // getting the last digit
        binary=binary/10;
        decimal +=remainder*pow(2,i);//finding 2^i*digit
        i++;
    }
    cout<<"Decimal number is "<<decimal;
}

Also See Program To Perform Operations On Queue

Output: