[Python Edinburgh] Pub Meetup Tomorrow: Who's Coming?

Mark Smith mark.smith at practicalpoetry.co.uk
Tue Oct 26 15:02:54 CEST 2010


You can also mask-out characters you're not interested in (I don't know if
python2.5 will do the int() conversion with base 2 below... it might do.):

def bits(v): return int(v, 2) # returns an int for a binary string
bits_i_care_about = bits('0b1001') # Your bitmask - removes bits you don't
care about
expected_value = bits('0x1000') # Your expected value - masked-out values
will be 0.

# Use mask to remove bits you don't care about, then check the result
against expected value (bit 3 high, bit 0 low, all others 0):
if (y & bits_i_care_about) == expected_value:
    print 'yay!'

--Mark

On 26 October 2010 13:52, Mark Smith <mark.smith at practicalpoetry.co.uk>wrote:

> Great to hear that you're coming.
>
> I haven't tested the following, but maybe it helps?
>
> def check_bit(bit, value):
>     mask == 0x1 >> bit
>     return (value & mask) == mask
>
> if check_bit(3, y) and not check_bit(0, y):
>     print 'yay!'
>
> --Mark
>
>
> On 26 October 2010 13:04, Ed HAWKINS <ed.hawkins at st.com> wrote:
>
>>  Hi all,
>>
>>
>>
>> I hope to come along tonight.
>>
>>
>>
>> Simple(?) python question:
>>
>>
>>
>> Suppose I have a variable, y, which contains a binary number (4 bits,
>> (3:0)). I want to compare individual bits within y and return True if some
>> of the bits are set/clear.
>>
>>
>>
>> For example, suppose I want to check bit3 is set and bit0 is clear... At
>> present I have:
>>
>>
>>
>> (y & 0x08) == 8 and (y & 0x01) == 0
>>
>>
>>
>> which seems a bit clunky (especially since I want to set up a dictionary
>> of possible compares). Is there a better way to do it?
>>
>>
>>
>> I suppose I really want to match the ‘pattern’ 0b1XX0 with y (where X is
>> don’t care)...
>>
>>
>>
>> Thanks, Ed.
>>
>>
>>
>>
>>
>> *From:* edinburgh-bounces+ed.hawkins=st.com at python.org [mailto:
>> edinburgh-bounces+ed.hawkins <edinburgh-bounces%2Bed.hawkins>=st.com@
>> python.org] *On Behalf Of *Mark Smith
>> *Sent:* 26 October 2010 12:51
>> *To:* The list for Pythonistas in Edinburgh.;
>> edinburgh-pug at googlegroups.com
>> *Subject:* Re: [Python Edinburgh] Pub Meetup Tomorrow: Who's Coming?
>>
>>
>>
>> Table booked for 8 people, for 6:30pm at Berts Bar (I'm assuming we'll get
>> a couple of extra people at the last minute - although it has just occurred
>> to me that Derek won't be along until later - ah well, no matter.)
>>
>>
>>
>> Look forward to seeing you all there!
>>
>>
>>
>> --Mark
>>
>> On 25 October 2010 14:16, Derek Hoy <derek.hoy at gmail.com> wrote:
>>
>> I'll be along later, so no pie for me.
>>
>> Derek
>>
>> On Mon, Oct 25, 2010 at 10:37 AM, Mark Smith
>>
>> <mark.smith at practicalpoetry.co.uk> wrote:
>>
>> > Hi All,
>> > There's a Pub Meetup tomorrow (Tuesday!) -- same details as before:
>> Bert's
>> > Bar[1] from 6:30pm, followed by a switch to Teuchters across the road
>> after
>> > we've eaten (7:30ish). Please mail the list (or me) if you plan to come
>> so I
>> > can get an idea of numbers for the table booking. Unexpected arrivals
>> are
>> > always welcome, but have a reduced chance of getting a seat :-)
>> > Don't forget that if you use Google Calendar, or a calendar that can
>> take
>> > iCal, you can subscribe to the calendar feeds on the site[2].
>> > --Mark
>> > 1: http://www.bertsbar.co.uk/berts-bar/home/berts-bar-edinburgh.html
>> > 2: http://www.pythonedinburgh.org/
>>
>> > _______________________________________________
>> > Edinburgh mailing list
>> > Edinburgh at python.org
>> > http://mail.python.org/mailman/listinfo/edinburgh
>> >
>> >
>> _______________________________________________
>> Edinburgh mailing list
>> Edinburgh at python.org
>> http://mail.python.org/mailman/listinfo/edinburgh
>>
>>
>>
>> _______________________________________________
>> Edinburgh mailing list
>> Edinburgh at python.org
>> http://mail.python.org/mailman/listinfo/edinburgh
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edinburgh/attachments/20101026/a57833e5/attachment-0001.html>


More information about the Edinburgh mailing list