From 177b9cb52e57da4e62dd8483bcd5905990d03f9e Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Mon, 19 Feb 2024 08:50:09 +0100 Subject: 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> --- Doc/library/struct.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index e2e6fc5..3e507c1 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('