Can string formatting be used to convert an integer to its binary form ?
flupke
flupke at nonexistingdomain.com
Thu Sep 28 03:27:05 EDT 2006
fdu.xiaojf at gmail.com schreef:
> Hi,
>
> 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 ?
>
>
> Thanks in advance.
>
> xiaojf
I don't actually know how to do it with string formatting but you can
create a simple function to do it.
Here's an example:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/219300
Regards,
Benedict
More information about the Python-list
mailing list