On Nov 16, 2007 4:08 PM, Gian Mario Tagliaretti <[EMAIL PROTECTED]> wrote:

Una soluzione 'string based' è:

convert = {
        '0' : '0000',
        '1' : '0001',
        '2' : '0010',
        '3' : '0011',
        '4' : '0100',
        '5' : '0101',
        '6' : '0110',
        '7' : '0111',
        '8' : '1000',
        '9' : '1001',
        'a' : '1010',
        'b' : '1011',
        'c' : '1100',
        'd' : '1101',
        'e' : '1110',
        'f' : '1111',
}

print ''.join([convert[c] for c in hex(23675)[2:]])

Non è particolarmente efficiente, ma lo trovo piuttosto leggibile.
-- 
-enrico
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a