这是 c++ 中的一个函数,它接受一个 HEX 字符串并将其转换为等效的 ASCII 字符。
string HEX2STR (string str)
{
string tmp;
const char *c = str.c_str();
unsigned int x;
while(*c != 0) {
sscanf(c, "%2X", &x);
tmp += x;
c += 2;
}
return tmp;
如果输入以下字符串:
537461636b6f766572666c6f77206973207468652062657374212121
输出将是:
Stackoverflow is the best!!!
假设我要在这个函数中输入 1,000,000 个唯一的 HEX 字符串,计算需要一段时间。
有没有更有效的方法来完成这个?