16进制字符串转成整型

    技术2026-05-17  8

    // 将16进制字符串转成int类型, 比如: s_hex = "FFFF",  return-> 65535, HTTP chunked的时候会用到 int HexStrToInt(char *s_hex) {     int ret = 0, i = 0, temp = 0;     char *pos = s_hex + strlen(s_hex) - 1;         while (pos >= s_hex)     {         if ('0' <= *pos && *pos <= '9')             temp = *pos - '0';         else if ('a' <= *pos && *pos <= 'f')             temp = *pos - 'a' + 10;         else if ('A' <= *pos && *pos <= 'F')             temp = *pos - 'A' + 10;         else             continue;         temp <<= i;         ret ^= temp;         i += 4;         --pos;     }     return ret; }

    最新回复(0)