SA-MP Forums Archive
Need help finding something - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help finding something (/showthread.php?tid=308103)



Need help finding something - LiamM - 02.01.2012

Hey guys, does anyone remember the post with two stocks. One called 'HexToInt' and the other 'IntToHex' I can't seem to find it anymore, does anyone have the snippet of code or even better the URL to the post? Thanks


Re: Need help finding something - Konstantinos - 02.01.2012

You can search on ******
pawn Код:
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;
}
pawn Код:
stock IntToHex(number)
{
    new m=1;
    new depth=0;
    while (number>=m) {
        m = m*16;
        depth++;
    }
    depth--;
    new str[256];
    for (new i = depth; i >= 0; i--)
    {
        str[i] = ( number & 0x0F) + 0x30; // + (tmp > 9 ? 0x07 : 0x00)
        str[i] += (str[i] > '9') ? 0x07 : 0x00;
        number >>= 4;
    }
    if(strlen(str) == 0)strins(str,"00",0);
    else
    if(strlen(str) == 1)strins(str,"0",0);
    str[8] = '\0';
    return str;
}



Re: Need help finding something - LiamM - 02.01.2012

Oh thanks man! I repped you for this!