I would like to change a Binary Number to a Decimal Number.
My problem is that my programme would not enter even the for
loop, hence my sum is always 0. I don't know where is the error of my for
loop.
My idea is that for a number like 1010, I will divide it by 10 and get the last digit which is 0, and then multiply it with 2^0, and then 1010 will be divide by 10 to be 101 and the loop continues.
Here is what i have tried so far:
cout<<"Please Enter a Binary Digit Number"<<endl;
cin>>num;
sum=0;
x=0;
for (int i=num; i/10 == 0; i/10) {
sum+=num%10*2^x;
num/=10;
x++;
}
cout<<sum;