I haven't tested it, but this method here should do the trick and is much saner in the handling of the string:

Code:
var cltext_hextovar(STRING *hexs, var *output)
{
    if(!hexs || !output)
        return -1;

    if(str_len(hexs) > 2)
        return -2;
        
    const char *hex = hexs->chars;
    int acc = 0;
    
    while(*hex)
    {
        char c = *(hex ++);
        
        if(c >= '0' && c <= '9)
            c -= '0';
        else if(c >= 'A' && <= 'Z')
            c -= 'A' - 10;
        else if(c >= 'a' && <= 'z')
            c -= 'a' - 10; 
        else
            return -3;
            
        acc = (acc * 16) + c;
    }
    
    *output = acc;
    return 0;
}



Further more, it can be expanded to convert strings with any base, by simply replacing the 16 in line 27 with the required base (and by adding a sanity check wether c is inside the base). Also, Kartoffel, could you please not post screenshots of code? I would have loved to copy and paste it instead of having to write the whole body myself.

(PS: Lemming: It's your code, you should be the one who maintains it in the git repo ;))

Last edited by Wiseguy; 05/27/13 23:32. Reason: Fixed two things

His words are wise, his face is beard.