struct.unpack() and bit operations
Peter Otten
__peter__ at web.de
Thu Sep 23 12:50:34 EDT 2004
mikeSpindler wrote:
> Is there an easier way to either get 16-bit "unpacks" or grab the
> upper 16-bits with success?
You may have a look at the array module:
>>> binary_data = "PleaseDon'tShout"
>>> a = array.array("H", binary_data)
>>> a
array('H', [27728, 24933, 25971, 28484, 10094, 21364, 28520, 29813])
>>> a[::2]
array('H', [27728, 25971, 10094, 28520])
>>> a[1::2].tostring()
'eaDotSut'
>>>
Peter
More information about the Python-list
mailing list