Skip to content

Bit field order changes depending on endianness. Is this intentional? #289

@Lezvix

Description

@Lezvix

I noticed that when using bitX() fields, the generated code changes the bit order depending on the selected endianness.

With .endianness("little"):

vars.b1 = $tmp0 >> 0 & 0x1;
vars.b2 = $tmp0 >> 1 & 0x1;
vars.b3 = $tmp0 >> 2 & 0x1;
vars.b4 = $tmp0 >> 3 & 0x1;

With .endianness("big"):

vars.b1 = $tmp0 >> 7 & 0x1;
vars.b2 = $tmp0 >> 6 & 0x1;
vars.b3 = $tmp0 >> 5 & 0x1;
vars.b4 = $tmp0 >> 4 & 0x1;

Since bit fields are extracted from a single byte (getUint8), and endianness typically affects only multi-byte values (e.g., uint16, uint32), I would not expect bit order within a byte to change.

Is this behavior intentional?
Why does endianness affect the order of bits inside a single byte?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions