[Tutor] Dealing with bitfields in Python
Alan Gauld
alan.gauld at btinternet.com
Sun Aug 30 19:58:09 CEST 2009
"Skipper Seabold" <jsseabold at gmail.com> wrote
> You can just do a binary AND with your consts and your bitfield value to
> get
> > each bit. The values will be the actual value (2, 4, 8, etc.) but if
> > you
> > use these as a boolean it won't matter.
> No that's perfect. It looks like I need to read up a bit more (pun
> not intended) on the binary AND, but I think I see what it does and I
> understand your example.
You can go to the Using the OS topic in my tutorial for a quick tutoerial
on how to extracts bits from a bitfield. There is a "sidebar" box entitled
"Bitwise Operations and Flags" which explains the idea
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list