Skip to content

Hex adapter uses wrong size for bitwise fields such as Nibble #1050

@jremus

Description

@jremus

In Construct 2.10.69 the Hex() adapter uses the number of bits as number of bytes when formatting BitsInteger() fields, such as Nibble(). It should detect that it is used on a bitwise field and compute the number or nibbles (or bytes) from the number of bytes, rounded up towards the next full integer.

Minimal example:

from construct import *

d = BitStruct("a" / Hex(Nibble), "b" / Nibble)
print(d.parse(b"\x42"))

Result:

Container:
    a = 0x00000004
    b = 2

Expected result:

Container:
    a = 0x4   (or 0x04)
    b = 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions