On this page
ctypes.BigEndianUnion
Prev: ctypes.BigEndianStructure | Up: ctypes | Next: ctypes.byref
Rel: ctypes.addressof, ctypes.alignment, ctypes.ArgumentError, ctypes.Array
Ref: docs.python.org — ctypes.BigEndianUnion
Tags: #public #python3 #stdlib #ctypes
Import
import ctypes
from ctypes import BigEndianUnion
Signature & Overview
ctypes.BigEndianUnion(...)
Union with big endian byte order
Usage
import ctypes
class Raw32(ctypes.BigEndianUnion):
_fields_ = [("u32", ctypes.c_uint32), ("bytes", ctypes.c_uint8 * 4)]
u = Raw32(u32=0x01020304)
assert list(u.bytes) == [1, 2, 3, 4]
Gotchas
- All fields share the same memory: Great for inspecting big-endian bit/byte layouts.
REPL Inspect
from ctypes import BigEndianUnion
help(BigEndianUnion)
Linked from
Related notes
- tuts/python3/stdlib_module/ctypes/BigEndianStructure Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/byref Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ctypes/addressof Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/alignment Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/ArgumentError Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/Array Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_bool shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_buffer shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_byte shared tags: #ctypes, #stdlib