]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Docs: Add explanation about little/big endian (#109841)
authorSimon A. Eugster <simon.eu@gmail.com>
Mon, 19 Feb 2024 07:50:09 +0000 (08:50 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Feb 2024 07:50:09 +0000 (23:50 -0800)
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 e2e6fc542e3e6710bd34625b1dcc382457d514d4..3e507c1c7e7c85c4577c905735b8d85f0f35881e 100644 (file)
@@ -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('<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.