十六进制转十进制

来源:互联网 发布:微信支付网页授权域名 编辑:程序博客网 时间:2024/06/05 14:29
int hexToInt(const char *str){    std::string string = str;    std::string charStr = "0123456789abcdefABCDEF";    int size = string.length();    if (size <= 0) {        return 0;    }    int *charArray = new int[size];    for (int index = 0; index < size; index++) {        int location = charStr.find(string[index]);        if (location >= 0) {            if (location >= 16) {                location -= 6;            }        }else{            //未找到            location = 0;        }        charArray[index] = location;    }        int value = 0;    for (int index = 0; index < size; index++) {        int valueOne = charArray[index];        value += (1<<(4*(size-1-index)))*valueOne;    }        delete [] charArray;        return value;}

0 0
原创粉丝点击