8000 Docs: Add explanation about little/big endian (#109841) · python/cpython@177b9cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 177b9cb

Browse files
GranjowAA-Turnerhauntsaninja
authored
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>
1 parent 53d5e67 commit 177b9cb

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
@@ -160,6 +160,21 @@ following table:
160160

161161
If the first character is not one of these, ``'@'`` is assumed.
162162

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

0 commit comments

Comments
 (0)
0