At Thursday 28/9/2006 22:07, Lawrence D'Oliveiro wrote:

How about this: (where n is the integer you want to convert):

"".join([["0", "1"][(1 << i & n) != 0] for i in range(int(math.ceil(math.log(n, 2))) - 1, -1, -1)])

Uhm... so to generate a binary string you have to import the math module, convert the integer to float, compute a non-standard logarithm, and then...
What if n<=0?
Too much, don't you think? :)


Gabriel Genellina
Softlab SRL

        
        
                
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! http://www.yahoo.com.ar/respuestas

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to