Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'referring': 0.07; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'marker': 0.16; 'match:': 0.16; 'quoted': 0.16; 'right:': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'skip:1 30': 0.19; 'written': 0.21; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; "i've": 0.25; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'context,': 0.31; 'url:wikipedia': 0.31; 'text': 0.33; 'something': 0.35; 'case,': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'combination': 0.36; 'false': 0.36; 'right?': 0.36; 'url:org': 0.36; 'so,': 0.37; 'sometimes': 0.38; 'convention': 0.38; 'needed': 0.38; 'list,': 0.38; 'pm,': 0.38; 'mailing': 0.39; 'called': 0.40; 'most': 0.60; 'no.': 0.61; "you're": 0.61; "you'll": 0.62; 'more': 0.64; 'forward': 0.65; 'underneath': 0.84; 'absolutely': 0.87; '2-5': 0.91; 'to:none': 0.92 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:cc :content-type; bh=PPFSkZKZV7f5E10UgCSOt3u4YpS/PjVJUaUAZF4x7fA=; b=wylXDm6gqBWjlzdFcP+hSXHvcmaKeEkh7hbJErEMQxP82kAye6uwxjAgPOrBwgsmdF wdUDhjoD2hVTqV3qNEV+kEfW1+kN+ppswwcG2mBjiUKrF83fj47n6frcn22swYIwW8/g AK0y9MCzLA7cY6l5l5ppe9KP43Uq8ZbYCOzByzbBN/CSqjizyT2QaECPSQTtooHgLqjc 9abx+pf+xL+1HlYFNCzrZm0HMLjkrq00Tv7GHEtsvOV74eHvoAP0+RfsoZp7V6LTnLvL /LH84HCEkRvnOePnAE2nRHxxqccINMx8wOmHrWgQI2/PawDvLCH/nn6atkM6/zsCuS31 eO4g== MIME-Version: 1.0 X-Received: by 10.42.128.4 with SMTP id k4mr14765994ics.8.1413616240114; Sat, 18 Oct 2014 00:10:40 -0700 (PDT) In-Reply-To: References: Date: Sat, 18 Oct 2014 18:10:40 +1100 Subject: Re: Extract Indices of Numpy Array Based on Given Bit Information From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413616243 news.xs4all.nl 2913 [2001:888:2000:d::a6]:51157 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79260 On Sat, Oct 18, 2014 at 6:02 PM, Artur Bercik wrote: > So, the Bit No. 2-5 for the following case is '1101', right? > > 1073741877: 1000000000000000000000000110101 > > If my required bit combination for Bit No. 2-5 is '1011', then the above > number (1073741877) is not chosen, right?? > > Look forward to know your confirmation. (Side point: Please don't top-post. The convention on this mailing list, and most other technical mailing lists, is what's sometimes called "interleaved style"; you trim the quoted text to what's needed for context, and put your text underneath what you're referring to. See https://en.wikipedia.org/wiki/Posting_style#Interleaved_style for more info.) >>> 1073741877&60 52 >>> bin(52) '0b110100' Everything I've written with the triple-angle-bracket marker can be typed in at the Python prompt, and you'll see exactly what it does. In this case, you can see that you're absolutely right: 1073741877 has 1101 in those positions, so if you're looking for 1011, it won't match: >>> 0b101100 44 However, 1073741869 would: >>> 1073741869&60 44 The way to test would be something like this: >>> (1073741877 & 0b111100) == 0b101100 False >>> (1073741869 & 0b111100) == 0b101100 True ChrisA