int hexToInt(const char *str)
{
std::string string = str;
std::string charStr = "0123456789abcdefABCDEF";
int size = string.length();
if (size <= 0) {
return 0;
}
int *charArray = new int[size];
for (int index = 0; index < size; index++) {
int location = charStr.find(string[index]);
if (location >= 0) {
if (location >= 16) {
location -= 6;
}
}else{
//未找到
location = 0;
}
charArray[index] = location;
}
int value = 0;
for (int index = 0; index < size; index++) {
int valueOne = charArray[index];
value += (1<<(4*(size-1-index)))*valueOne;
}
delete [] charArray;
return value;
}
十六进制转十进制
最新推荐文章于 2023-11-15 21:15:01 发布