SA-MP Forums Archive
[Pedido] Color Hexadecimal to Decimal - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Pedido] Color Hexadecimal to Decimal (/showthread.php?tid=532240)



Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Alguem me arranja um stock para fazer isso ?


Re: Color Hexadecimal to Decimal - PT - 17.08.2014

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
pawn Код:
stock BaseToInt(string[], const base) {
    if(string[0] && (1 < base < 37)) {
        new
            res = 0,
            cur = 1,
            i = strlen(string);
        for( ; (--i) != -1; cur *= base)
            switch(string[i]) {
                case '0'..'9': res += (cur * (string[i] - '0'));
                case 'a'..'z': res += (cur * (string[i] - 'a' + 10));
                case 'A'..'Z': res += (cur * (string[i] - 'A' + 10));
                default: return 0;
            }
        return res;
    }
    return 0;
}
#define DualToInt(%0) BaseToInt(%0, 2)
#define OctalToInt(%0) BaseToInt(%0, 8)
#define HexToInt(%0) BaseToInt(%0, 16)
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)
tens ai


Re: Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Obrigado PT !


Re: Color Hexadecimal to Decimal - Schocc - 17.08.2014

Se precisar da entrada por corda(string).
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;
}



Re: Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Tentei converter esta cor: #0000FF mas da preto, podem-me ajudar ? (Dб 255)


Re: Color Hexadecimal to Decimal - Schocc - 17.08.2014

Quote:
Originally Posted by VeNuZ_
Посмотреть сообщение
Tentei converter esta cor: #0000FF mas da preto, podem-me ajudar ? (Dб 255)

Logicamente esta correto #'00'00'FF vai dar 255 em blue R'G'B...

O que vocк pretende fazer ?


Re: Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Eu coloco, 255 e dб preto..


Re: Color Hexadecimal to Decimal - Schocc - 17.08.2014

Exatamente, vocк precisa ler este tutorial se quer entender mais sobre cores.
https://sampforum.blast.hk/showthread.php?tid=200876


Re: Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Entгo, mas se eu converti o azul, nгo devia dar azul ?


Re: Color Hexadecimal to Decimal - VeNuZ_ - 17.08.2014

Alguem ?