On 06/15/2011 07:33 AM, Daniel Rentz wrote:
Am 15.06.2011 14:29, schrieb Olivier LEMAIRE:
Hi there, I've been looking for 2 days for a way to convert integer
to binary number 0-padded, nothing... I need to get numbers converted
with a defined number of bits. For example on 8 bits 2 = 00000010
bin(2)[2:].zfill(8)
Just to have in the thread (though the OP seems to be using 2.6
or later), the bin() function appears to have been added in 2.6
which is something I wish had been back-ported to 2.4 and 2.5 as
I've been sufficiently stuck coding against older versions of
Python to have (re)written a bin() function multiple times. Ah well.
-tkc
--
http://mail.python.org/mailman/listinfo/python-list