Manipulating bitsets in struct
Larry Bates
larry.bates at websafe.com`
Wed Jul 9 20:27:17 EDT 2008
Allen wrote:
> I'm using Python to do some simple network programming, and found the
> struct module very useful for such things, but is there a way to easily
> manipulate bitsets such as a 16 bit word being split into 4 parts like 2
> bits, 1 bit, 4 bits, and 9 bits?
>
> Perhaps something like:
>
> struct.pack('!h(2:1:4:9)',2,0,1,100)
>
>
> Brian Vanderburg II
>
>
>
>
>
Just 'or' them together after shifting to the left the appropriate number of bits.
-Larry
More information about the Python-list
mailing list