]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Docs: Add explanation about little/big endian (GH-109841) (#115646)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 19 Feb 2024 07:56:54 +0000 (08:56 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Feb 2024 07:56:54 +0000 (07:56 +0000)
Docs: Add explanation about little/big endian (GH-109841)
(cherry picked from commit 177b9cb52e57da4e62dd8483bcd5905990d03f9e)

Co-authored-by: Simon A. Eugster <simon.eu@gmail.com>
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

index c94dfde4d55763f2774d3bde333c66a8af59f5d9..5de003f95821fdd49c644d8ce66ea1ef884e974c 100644 (file)
@@ -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('<h', 1023)
+       b'\xff\x03'
+
 Native byte order is big-endian or little-endian, depending on the
 host system. For example, Intel x86, AMD64 (x86-64), and Apple M1 are
 little-endian; IBM z and many legacy architectures are big-endian.