From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 19 Feb 2024 07:57:00 +0000 (+0100) Subject: [3.11] Docs: Add explanation about little/big endian (GH-109841) (#115647) X-Git-Tag: v3.11.9~178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb759952eecdf2ffacb2ea31767e5084352d5b5d;p=thirdparty%2FPython%2Fcpython.git [3.11] Docs: Add explanation about little/big endian (GH-109841) (#115647) Docs: Add explanation about little/big endian (GH-109841) (cherry picked from commit 177b9cb52e57da4e62dd8483bcd5905990d03f9e) Co-authored-by: Simon A. Eugster 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 416b01db615f..54d717c53979 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -156,6 +156,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('