Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jremus opened this issue Nov 3, 2023 · 1 comment
Open

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

jremus opened this issue Nov 3, 2023 · 1 comment

Comments

@jremus
Copy link

jremus commented Nov 3, 2023

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
@arekbulski
Copy link
Member

Here is a PR that seems to be referring to same behavior: #1021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants