{
char revstr[16] = { 0 }; //根据十六进制字符串的长度,这里注意数组不要越界
int num[16] = { 0 };
int count = 1;
int result = -1;
if (NULL != str)
{
strncpy(revstr, str, length);
for (int i = length - 1; i >= 0; i--)
{
if ((revstr[i] >= ‘0‘) && (revstr[i] <= ‘9‘))
num[i] = revstr[i] - 48;//字符0的ASCII值为48
else if ((revstr[i] >= ‘a‘) && (revstr[i] <= ‘f‘))
num[i] = revstr[i] - ‘a‘ + 10;
else if ((revstr[i] >= ‘A‘) && (revstr[i] <= ‘F‘))
num[i] = revstr[i] - ‘A‘ + 10;
else
num[i] = 0;
result = result + num[i] * count;
count = count * 16;//十六进制(如果是八进制就在这里乘以8)
}
}
#ifdef __linux__
result++;
#endif
return result;
}
Why???!!!