8000 [3.12] Docs: Add explanation about little/big endian (GH-109841) (#11… · python/cpython@8a5731e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a5731e

Browse files
miss-islingtonGranjowAA-Turnerhauntsaninja
authored
[3.12] Docs: Add explanation about little/big endian (GH-109841) (#115646)
Docs: Add explanation about little/big endian (GH-109841) (cherry picked from commit 177b9cb) 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>
1 parent e25ac3b commit 8a5731e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Doc/library/struct.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ following table:
156156

157157
If the first character is not one of these, ``'@'`` is assumed.
158158

159+
.. note::
160+
161+
The number 1023 (``0x3ff`` in hexadecimal) has the following byte representations:
162+
163+
* ``03 ff`` in big-endian (``>``)
164+
* ``ff 03`` in little-endian (``<``)
165+
166+
Python example:
167+
168+
>>> import struct
169+
>>> struct.pack('>h', 1023)
170+
b'\x03\xff'
171+
>>> struct.pack('<h', 1023)
172+
b'\xff\x03'
173+
159174
Native byte order is big-endian or little-endian, depending on the
160175
host system. For example, Intel x86, AMD64 (x86-64), and Apple M1 are
161176
little-endian; IBM z and many legacy architectures are big-endian.

0 commit comments

Comments
 (0)
0