int main()
{
int N=0, counter=0, counter1=0,counter2=0, temp=0, temp1=0,dec=0,result=0, moder=0;
cout<<"Please enter required binary number"<<endl;
cin>>N;
temp=N;
while(temp>=10)
{
temp=temp/10;
moder=moder*10;
counter++;
}
counter2=counter+1;
while(counter1<=counter)
{
dec=(N%moder)*pow(2,counter2);
N=N-moder;
moder=moder/10;
counter2--;
result=result+dec;
counter1++;
}
cout<<"Decimal number will be "<<result<<endl;
return 0;
}
........................................................................................................................
This is Binary to Decimal Converter. It's not working. Although Dry Run of this program works fine. I don't know what's problem.
Can any one find it's bug or bugs and fix it for me. Thanks!
I have written a code recently that converts a Bin Num to Dec.
It looks like it works.
I put here the code for testing purposes.
Forum members, please, check it.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int N=1, counter=0, counter1=0, temp=1, result=0, moder=1;
cout<<"Please enter required binary number"<<endl;
cin>>N;
temp=N;
while(temp>=10)
{
temp=temp/10;
moder=moder*10;
counter++;
}
while(counter1<=counter)
{
temp= N/moder;
N=N-moder;
result +=(temp)*pow(2,counter);
moder=moder/10;
counter--;
counter1++;
}
cout<<"Decimal number will be "<<result<<endl;
return 0;
}
Thankyou all of you. I have found solution.