SA-MP Forums Archive
Integer to Hex - 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: Integer to Hex (/showthread.php?tid=218179)



Integer to Hex - me-borno - 29.01.2011

Hello,

i know this question is asked allot, but not in the way i use it..
i save every player color in an Int, but now i want to use the color to work inside a string(0.3c'ish)
so that supposed to be like: "{FF000000}etc.." but how can i convert my Integer color to a Hex color?

someone told me sscanf could do it, but how and can it?

Already thanks! this will realy help me!

if this isn't clear enough.. ill try explain more..


Re: Integer to Hex - JaTochNietDan - 29.01.2011

After a quick search using the forums search function, I came up with this IntToHex function for Pawn.

pawn Код:
stock IntToBase(number, const base) {
    new str[32];
    if(1 < base < 37) {
        new
            m = 1,
            depth = 0;
        while (m <= number) {
            m *= base;
            depth++;
        }
        for ( ; (--depth) != -1; ) {
            str[depth] = (number % base);
            number = ((number - str[depth]) / base);
            if(str[depth] > 9) str[depth] += 'A'; else str[depth] += '0';
        }
    }
    return str;
}
#define IntToDual(%0) IntToBase(%0, 2)
#define IntToOctal(%0) IntToBase(%0, 8)
#define IntToHex(%0) IntToBase(%0, 16)



Re: Integer to Hex - me-borno - 29.01.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
After a quick search using the forums search function, I came up with this IntToHex function for Pawn.

pawn Код:
stock IntToBase(number, const base) {
    new str[32];
    if(1 < base < 37) {
        new
            m = 1,
            depth = 0;
        while (m <= number) {
            m *= base;
            depth++;
        }
        for ( ; (--depth) != -1; ) {
            str[depth] = (number % base);
            number = ((number - str[depth]) / base);
            if(str[depth] > 9) str[depth] += 'A'; else str[depth] += '0';
        }
    }
    return str;
}
#define IntToDual(%0) IntToBase(%0, 2)
#define IntToOctal(%0) IntToBase(%0, 8)
#define IntToHex(%0) IntToBase(%0, 16)
No joke! i love u! why couldn't i just find that :S
but.. it wont work,
i tried:
Код:
printf("%x", IntToHex(10));
printf("%s", IntToHex(10));
but both wont work :S


Re: Integer to Hex - Superthijs - 05.02.2012

When I use this code, 'ABCDEF' respectively appears as 'KLMNOP'. What's wrong?