From: Simon A. Eugster Date: Mon, 19 Feb 2024 07:50:09 +0000 (+0100) Subject: Docs: Add explanation about little/big endian (#109841) X-Git-Tag: v3.13.0a5~347 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=177b9cb52e57da4e62dd8483bcd5905990d03f9e;p=thirdparty%2FPython%2Fcpython.git Docs: Add explanation about little/big endian (#109841) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index e2e6fc542e3e..3e507c1c7e7c 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -160,6 +160,21 @@ following table: If the first character is not one of these, ``'@'`` is assumed. +.. note:: + + The number 1023 (``0x3ff`` in hexadecimal) has the following byte representations: + + * ``03 ff`` in big-endian (``>``) + * ``ff 03`` in little-endian (``<``) + + Python example: + + >>> import struct + >>> struct.pack('>h', 1023) + b'\x03\xff' + >>> struct.pack('