Re: Can string formatting be used to convert an integer to itsbinary form ?
At Thursday 28/9/2006 22:07, Lawrence D'Oliveiro wrote:
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!
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)])
>
"".join([["0", "1"][(1 << i & n) != 0] for i in
range(int(math. ceil(math.log(n , 2))) - 1, -1, -1)])
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!
Comment