2进制和10进制的转换?
#include <iostream>
using namespace std;
double power(double x,int n);
int main()
{
int i;
int value;
char ch;
cout<<"enter an 8 bit binary number";
for(i=7;i>=0;i--)
{
cin>>ch;
if(ch=='1')
value+=int(power(2,i));
}
cout<<"the total is"<<value<<endl;
}
double power(double x,int n)
{
double val=1.0;
while(n--)
val*=x;
return(val);
}假如输入01101001,运行结果真么和预期的比一样呢?