StringToHex
#3

Thanks for reply, but it doesn't work correctly. I don't know why, here is my test results:

pawn Код:
new
    string[ 50 ],
    hex
;
format( string, sizeof( string ), "%x%x", 0xFF0000, 17 );
sscanf( string, "x", hex );
printf( "sscanf: %d %x", hex, hex );
hex = HexToInt( string );
printf( "HexToInt: %d %x", hex, hex );

// above
stock HexToInt(string[])
{
    if (string[0] == 0)
    {
        return 0;
    }
    new i;
    new cur = 1;
    new res = 0;
    for (i = strlen(string); i > 0; i--)
    {
        if (string[i-1] < 58)
        {
            res = res + cur * (string[i - 1] - 48);
        }
        else
        {
            res = res + cur * (string[i-1] - 65 + 10);
            cur = cur * 16;
        }
    }
    return res;
}
Код:
[13:13:41] sscanf: -16777199 -FFFFEF
[13:13:41] HexToInt: 257 101
In this case, sscanf works properly. Don't ask, why I need it .
Reply


Messages In This Thread
StringToHex - by zgintasz - 13.06.2012, 09:51
Re: StringToHex - by Vince - 13.06.2012, 09:54
Re: StringToHex - by zgintasz - 13.06.2012, 10:07
Re: StringToHex - by MP2 - 13.06.2012, 10:18

Forum Jump:


Users browsing this thread: 2 Guest(s)