总结
- 八位的十六进制能够产生十位数的的十进制,int 类型不可取
- 转载一个关于 int 和 long 长度的文章
https://blog.csdn.net/lexiaowu/article/details/98767343
#include <iostream>
#include <math.h>
using namespace std;
int main() {
string str = "";
long long temp = 0;
cin >> str;
int n = str.length() - 1;
for (int i = 0; i <= n; ++i) {
if (str[i] - '0' >= 0 && str[i] - '0' <= 9) {
temp += (str[i] - '0') * pow(16, n - i);
} else {
temp += (str[i] - 'A' + 10) * pow(16, n - i);
}
}
cout << temp << endl;
return 0;
}