[docs] Documentation bug: struct library, endian format chars are reversed

Tom Belpasso tombelpasso at gmail.com
Sat Aug 31 18:37:42 EDT 2019


Dear Python Docs:

The struct library has table with format values for pack and unpack.
In section: 7.1.2.1. Byte Order, Size, and Alignment

The big endian and little endian characters are reversed in the table.

'>' should be little endian, just like the character looks.
'<' should be big endian, just like the character.

I have verified that this is the correct behavior after use the wrong one
in my program and wondering why I was seeing so many large fluctuations in
my plots. I had wasted many day's rewiring my prototype to get rid of the
noise.  It turned out it was just the byte order of my 16bit data what was
getting misinterpreted.

I found the problem, when I was attempting to write a WAV format file,
which is big endian and it was coming out backwards!

To verify my assertion:
## hex 16 bit number is the bytes for H and L, where 'H' is MS byte
struct.pack('<H',0x484c)
# should return: 'b'LH' which is big endian, 'H' is at the end.

struct.pack('>H',0x484c)
# should return: 'b'HL'

Thank you for your hard work.

Kind regards,
Tom Belpasso
Integrated Vision
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20190831/33e71347/attachment.html>


More information about the docs mailing list