Writing C readable bitfield structs?

Larry Bates lbates at syscononline.com
Wed Mar 16 12:32:02 EST 2005


phark52 at yahoo.com wrote:
> How would I go about writing a bitfield that can be read by my C app? I
> want to pack a few bools into one int.
> 
> I know an extended module exists (npstruct) which helps you do this but
> I want to do it manually or using one of the standard modules.
> 
struct.pack is in the Standard Library and allows you to do what
you want.  You may find that you must also do some "bit twiddling"
using << shift functions and | bit or function if you want to pack
tighter than on 4 bit boundaries.

Larry Bates



More information about the Python-list mailing list