Convert integer to fixed length binary string

Mark Dickinson dickinsm at
Thu Jun 11 06:01:43 EDT 2009

On Jun 11, 10:29 am, casebash <walkr... at> wrote:
> Sorry, I didn't quite make it clear. The issue isn't about limiting
> the length (as I won't be using integers bigger than this). The
> problem is that sometimes the output is shorter.

Is this what you're looking for?

Python 2.6.2 (r262:71600, Jun  8 2009, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0:032b}'.format(12345)


More information about the Python-list mailing list