Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Please add documentation of the bitfield ordering for ctypes.Structure types #118434

Copy link
Copy link
Open
@TomCulliton

Description

@TomCulliton
Issue body actions

Documentation

The current documentation for ctypes bit fields is very limited and doesn't cover the definition order. AFAICT this is:
Little endian - LSB first -> MSB last
Big endian - MSB first -> LSB last
Native - ??? This is LSB first -> MSB last on x86 but is that just because it's a little endian architecture?

For example:

class BigOnes(BigEndianStructure):
   _pack_ = 1
    _fields_ = (
        ("bit_0", c_uint16, 1),  # MSBit
        ("bit_1", c_uint16, 1),
        ("bit_2", c_uint16, 1),
        ("bit_3", c_uint16, 1),
        ("nibble_1", c_uint16, 4),
        ("nibble_2", c_uint16, 4),
        ("nibble_3", c_uint16, 4),  # LSBit
        ("byte_3", c_uint16, 8),  # MSByte
        ("byte_4", c_uint16, 8),  # LSByte
    )

Versus:

class LittleOnes(LittleEndianStructure):
    _pack_ = 1
    _fields_ = (
        ("bit_0", c_uint16, 1),  # LSBit
        ("bit_1", c_uint16, 1),
        ("bit_2", c_uint16, 1),
        ("bit_3", c_uint16, 1),
        ("nibble_1", c_uint16, 4),
        ("nibble_2", c_uint16, 4),
        ("nibble_3", c_uint16, 4),  # MSBit
        ("byte_3", c_uint16, 8),  # LSByte
        ("byte_4", c_uint16, 8),  # MSByte
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.