I have a Python array('B')
(containing some data read from a file), which I would like to convert to an array('H')
. I am currently using code similar to the following:
a = array.array('B', f.read())
b = a[16:32]
c = array.array('H', b.tostring())
Unfortunately the conversion in the third line uses the native byte order, so will give different results on different machines.
Is there any way to make the conversion always little-endian, irrespective of the native byte order?