String to HEX
#1

Hello guys,

I've searched for this, but I did not find it.
I need a function that converts a string (Inputtext at Dialog) to a Hex, which gets stored afterwards in a variable.

Ex:
pawn Код:
MyHexVar = StringToHex(inputtext);
TextDrawColor(MyTextDraw, MyHexVar);
That's what I need. I hope someone can help me.


Greetings,
Jeffry
Reply
#2

No reply after 2 days.
Is there no such function, or just any way?
Reply
#3

https://sampwiki.blast.hk/wiki/Colors_List

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;
}
Reply
#4

Alright, thanks Vince, I'll try this out soon (Busy alot^^).

@******: I searched on forums at all, but okey, I'll check there next time.


EDIT: The function of Vince doesn't work correctly.
But the link helped, DracoBlue's one works.

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)