[Pedido] Color Hexadecimal to Decimal
#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


Messages In This Thread
Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 10:13
Re: Color Hexadecimal to Decimal - by PT - 17.08.2014, 10:40
Re: Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 10:54
Re: Color Hexadecimal to Decimal - by Schocc - 17.08.2014, 11:14
Re: Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 11:21
Re: Color Hexadecimal to Decimal - by Schocc - 17.08.2014, 12:32
Re: Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 12:49
Re: Color Hexadecimal to Decimal - by Schocc - 17.08.2014, 12:56
Re: Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 14:00
Re: Color Hexadecimal to Decimal - by VeNuZ_ - 17.08.2014, 19:56

Forum Jump:


Users browsing this thread: 1 Guest(s)