#include<iostream>
#include<string>
#include<cmath>
using namespace std;
bool change(string a, int n)
{
int sum = 0;
int x ,tmp,j,b;
for(int i=n,x=0;i>0;i--,x++)
{
if((a[x]>='0')&&(a[x]<='9'))
{
b = a[x]-'0';
tmp = 1;
j = i-1;
tmp = pow(16,j); //16的次方
tmp = tmp * b;
sum = sum + tmp;
}
else if((a[x]>='a')&&(a[x]<='f'))
{
b = a[x]-'a'+10;
tmp = 1;
j = i-1;
tmp = pow(16,j);
tmp = tmp * b;
sum = sum + tmp;
}
else if((a[x]>='A')&&(a[x]<='F'))
{
b = a[x]-'A'+10;
tmp = 1;
j = i-1;
tmp = pow(16,j);
tmp = tmp * b;
sum = sum + tmp;
}
else
{
cout<<"输入数据有问题:"<<endl;
return false;
}
}
cout<<"十进制数为:"<<sum<<endl;
return true;
}
int main(int argc, char** argv)
{
int n;
string a;
cout<<"请输入16进制的字符串:";
cin>>a;
n = a.size();
change(a,n);
}