代码实现:
#include<iostream> using namespace std; long fun(char *s) { int i,t; long sum=0; for(i=0;s[i];i++) { if(s[i]<='9') t=s[i]-'0'; else t=s[i]-'a'+10; sum=sum*16+t; } return sum; } main() { long m; char s[50]; cout<<"请输入十六进制数: "; cin>>s; m=fun(s); cout<<"十进制数为:"<<m<<endl; }
运行结果: