#include "windows.h"
#include<cstdlib>
//参考ASCII码表设计
static int hex_table[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 10,
11, 12, 13, 14, 15 };
int hex_to_decimal(char* hex_str)//简单strtol底层实现方法
{
char ch;
int iret = 0;
while (ch = *hex_str++)
{
iret = (iret << 4) | hex_table[ch];
}
return iret;
}
int main()
{
int n = _countof(hex_table);
int c = hex_to_decimal(const_cast<char*>("1E2E"));
int a = strtol("1E2E",nullptr,16);
return 0;
}
参考:https://blog.csdn.net/qq_21095573/article/details/106234919