markparticle / WebServer

C++ Linux WebServer服务器
Apache License 2.0
3.49k stars 730 forks source link

converHex将字符转换成整数 #72

Open ruiidong opened 1 year ago

ruiidong commented 1 year ago

应该return ch-'0'才对吧?

peng-yq commented 4 months ago

应该return ch-'0'才对吧?

int HttpRequest::ConvertHexToDec(char ch) {
    // ConvertHexToDec is only called when processing hexadecimal
    // so does not handle the situation 
    // where ch is not a hexadecimal character
    if (ch >= '0' && ch <= '9') {
        return ch - '0';
    }
    if (ch >= 'A' && ch <= 'F') {
        return ch - 'A' + 10;
    }
    if (ch >= 'a' && ch <= 'f') {
        return ch - 'a' + 10;
    }
}