[Pedido] Color Hexadecimal to Decimal
#1

Alguem me arranja um stock para fazer isso ?
Reply
#2

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
Reply
#3

Obrigado PT !
Reply
#4

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

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

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 ?
Reply
#7

Eu coloco, 255 e dб preto..
Reply
#8

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

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

Alguem ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)