Wednesday 4 June 2014

Binary to Decimal Conversion

 // BINARY TO DECIMAL CONVERSION

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
    int number[15];
    for(int i=0;i<15;i++)
    {
        number[i]=0;
    }
    cout<<"enter the binary number"<<endl;
   
    int decimal=0;
    int k=14;
    for(int j=0;j<15;j++)
    {
        cin>>number[j];
    }
        for(int z=0;z<15;z++)
        {
                decimal=decimal+(number[z]*(pow(2,k)));
                k--;
        }
    cout<<decimal;
    getch();
    return 0;
}

No comments:

Post a Comment