Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bits': 0.07; 'python': 0.08; 'bits.': 0.09; 'am,': 0.14; 'binary': 0.14; 'wrote:': 0.14; 'defined': 0.14; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'cc:addr:python-list': 0.17; 'converted': 0.19; 'convert': 0.19; 'header:In-Reply-To:1': 0.21; 'appears': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; '(though': 0.23; '2.4': 0.23; 'integer': 0.23; 'versions': 0.23; 'function': 0.25; 'times.': 0.26; 'example': 0.27; 'cc:addr:python.org': 0.30; "i've": 0.33; 'daniel': 0.34; 'header:User-Agent:1': 0.35; '2.6': 0.35; 'stuck': 0.35; 'using': 0.35; 'something': 0.37; 'coding': 0.37; 'thread': 0.37; 'subject:: ': 0.38; 'wish': 0.70; '07:33': 0.84; 'schrieb': 0.84 Date: Wed, 15 Jun 2011 08:13:04 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Daniel Rentz Subject: Re: integer to binary 0-padded References: <5c29244e-41fe-4f19-80d1-83a2169b9cc9@glegroupsg2000goo.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308143602 news.xs4all.nl 49048 [::ffff:82.94.164.166]:52733 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7696 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