Can string formatting be used to convert an integer to its binary form ?
Gabriel Genellina
gagsl-py at yahoo.com.ar
Thu Sep 28 05:05:38 EDT 2006
At Thursday 28/9/2006 05:22, Mirco Wahab wrote:
> > String formatting can be used to converting an integer to its octal or
> > hexadecimal form:
> > >>> a = 199
> > >>> "%o" % a
> > '307'
> > >>> "%x" % a
> > 'c7'
> >
> > But, can string formatting be used to convert an integer to its binary
> > form ?
>
> a = 199
> a_bin_str = pack('L', a)
Notice that the OP was looking for another thing, given the examples.
Perhaps a better wording would have been "how to convert an integer
to its base-2 string representation".
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
More information about the Python-list
mailing list