Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'argument': 0.04; 'width': 0.07; 'page)': 0.09; "they've": 0.09; 'useless': 0.09; 'cc:addr:python-list': 0.10; '-tkc': 0.16; 'disclaimers': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'thoughts?': 0.16; 'wrote:': 0.17; 'byte': 0.17; '(not': 0.20; 'bit': 0.21; 'disclaimer': 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'dimensions': 0.29; 'could': 0.32; 'print': 0.32; 'anyone': 0.33; "can't": 0.34; 'robert': 0.35; 'posting': 0.35; 'something': 0.35; '(i.e.': 0.36; 'charset:us-ascii': 0.36; 'display': 0.36; 'does': 0.37; 'detail': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'possible.': 0.38; 'remove': 0.61; 'legal': 0.65; 'bitmap': 0.84; 'received:50.22': 0.84; 'standing': 0.84 Date: Tue, 12 Mar 2013 08:20:54 -0500 From: Tim Chase To: Robert Flintham Subject: Re: Reversing bits in a byte In-Reply-To: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 Cc: "'python-list@python.org'" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363097544 news.xs4all.nl 6951 [2001:888:2000:d::a6]:39658 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41124 On 2013-03-11 15:32, Robert Flintham wrote: > I have a 'bytes' object which contains a simple bitmap image (i.e. > 1 bit per pixel). I can't work out how I would go about displaying > this image. Does anyone have any thoughts? You'd need to detail - how you want to display it (console, GUI, web page) - how you know what the dimensions are - the bit order It could be something as simple as HEIGHT = 40 some_bytes = file('data.bin').read() WIDTH = len(some_bytes) // HEIGHT for i, byte in enumerate(some_bytes): if i and i % WIDTH == 0: print # a new line for bit in range(8): if byte & (1 << bit): print '*', else: print ' ', -tkc > DISCLAIMER: [trim a paragraph of useless junk] Please remove these disclaimers if at all possible. You're posting to a public forum, which pretty much waives all credibility to the disclaimer (not that they've held much legal standing in any argument I've heard).