Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7696

Re: integer to binary 0-padded

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 <python.list@tim.thechases.com>
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 <python.list@tim.thechases.com>
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 <daniel.rentz@gmx.de>
Subject Re: integer to binary 0-padded
References <5c29244e-41fe-4f19-80d1-83a2169b9cc9@glegroupsg2000goo.googlegroups.com> <ita8qe$iqn$1@news-cedar.fernuni-hagen.de>
In-Reply-To <ita8qe$iqn$1@news-cedar.fernuni-hagen.de>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2.1308143602.1164.python-list@python.org> (permalink)
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

Show key headers only | View raw


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


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

integer to binary 0-padded Olivier LEMAIRE <m.olivier.lemaire@gmail.com> - 2011-06-15 05:29 -0700
  Re: integer to binary 0-padded Daniel Rentz <daniel.rentz@gmx.de> - 2011-06-15 14:33 +0200
    Re: integer to binary 0-padded Tim Chase <python.list@tim.thechases.com> - 2011-06-15 08:13 -0500
  Re: integer to binary 0-padded Chris Angelico <rosuav@gmail.com> - 2011-06-15 22:48 +1000
  Re: integer to binary 0-padded Peter Otten <__peter__@web.de> - 2011-06-15 14:54 +0200

csiph-web