Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'binary': 0.07; 'subject:help': 0.08; 'subject:number': 0.09; '1111': 0.16; '23,': 0.16; 'be:': 0.16; 'bitwise': 0.16; 'for,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'thu,': 0.19; 'input': 0.22; 'example': 0.22; 'equivalent': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'rest': 0.29; 'message-id:@mail.gmail.com': 0.30; 'decimal': 0.31; 'figure': 0.32; 'received:google.com': 0.35; 'there': 0.35; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'results': 0.69; '0000': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=BygftcCFjTikbs/iaqdn9y9NnMc+7D7oETMeyV/NOXA=; b=YB5nD18YOFpIyhNiEm8zOFetY3I1AV/DIPWb57hpWKmtyQNFaXbw8a/fpKi2+JBBRi pIscXheJ3FWVh7J82jkPTqUhdh/jbW2INV3K0ftS+qq5bYFhxQgo8altkqx6sAghHFlo a/P715NNtC5UYgvMqSg3cyMjg3S4squOzjko/KhHG4v5j3d5BabzgMeg4Twj4qDIrQlB AjkAzOtpnLX8EEty5z9NkHiE7svVmQeK0U6vsKDHNjutedKDVwhtdXZyBtrWQVGEQlFA 4p4gqGagdw1I1zRcsHGfeFUmojLSeh+bs5IVD7TGPCqsFlT+sO05+2YJKpEdEhEaGy/F Ovzg== MIME-Version: 1.0 X-Received: by 10.52.117.16 with SMTP id ka16mr1480361vdb.43.1369309050657; Thu, 23 May 2013 04:37:30 -0700 (PDT) In-Reply-To: <7f794f03-03c9-44de-8312-4ad33b68c266@googlegroups.com> References: <7f794f03-03c9-44de-8312-4ad33b68c266@googlegroups.com> Date: Thu, 23 May 2013 21:37:30 +1000 Subject: Re: help in obtaining binary equivalent of a decimal number in python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369309056 news.xs4all.nl 15881 [2001:888:2000:d::a6]:42497 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45800 On Thu, May 23, 2013 at 9:30 PM, wrote: > i need to get 32 bit binary equivalent of a decimal and need to change the 0's to 1's and 1's to 0's > For Example > if the input is 2 > Output should be: > the 32bit equivalent of 2 :0000 0000 0000 0000 0000 0000 0000 0010 > and the 1's compliment is:1111 1111 1111 1111 1111 1111 1111 1101 > > > > is there any pre-defined function to get the above results in python?? You're asking for bitwise negation. Now that you know the keyword(s) to look for, you should be able to figure out the rest with a few quick docs and/or web searches. ChrisA