I want to build a small formatter in python giving me back the numeric values embedded in lines of hex strings.
It is a central part of my formatter and should be re
array.arrays
have a byteswap method:
import binascii
import struct
import array
x = binascii.unhexlify('b62e000052e366667a66408d')
y = array.array('h', x)
y.byteswap()
s = struct.Struct('
The h
in array.array('h', x)
was chosen because it tells array.array
to regard the data in x
as an array of 2-byte shorts. The important thing is that each item be regarded as being 2-bytes long. H
, which signifies 2-byte unsigned short, works just as well.