summaryrefslogtreecommitdiffstats
path: root/Doc/library/struct.rst
diff options
context:
space:
mode:
authorSimon A. Eugster <simon.eu@gmail.com>2024-02-19 07:50:09 (GMT)
committerGitHub <noreply@github.com>2024-02-19 07:50:09 (GMT)
commit177b9cb52e57da4e62dd8483bcd5905990d03f9e (patch)
tree42aeb2159fdcf498a8357a62b9ef13f54679f223 /Doc/library/struct.rst
parent53d5e67804227d541ed2f9e8efea8de5d70cb1ec (diff)
downloadcpython-177b9cb52e57da4e62dd8483bcd5905990d03f9e.zip
cpython-177b9cb52e57da4e62dd8483bcd5905990d03f9e.tar.gz
cpython-177b9cb52e57da4e62dd8483bcd5905990d03f9e.tar.bz2
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>
Diffstat (limited to 'Doc/library/struct.rst')
-rw-r--r--Doc/library/struct.rst15
1 files changed, 15 insertions, 0 deletions
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('<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.