Closed scandey closed 1 year ago
Thanks for reporting! I'll take a look at this tomorrow. There was a patch last week made to odd length negative int handling, which is probably related.
I think in your test data, your uintfive is actually 2 and negtwelve is actually -6. Can you double check this?
In [1]: from bitstring import BitArray
In [2]: arr = BitArray(bytes=b"\x00\x01\xC0\x00\x00\x03\x5B\x00\xCF\xFA")
In [3]: arr[48:51].uint
Out[3]: 2
In [4]: arr[-12:].int
Out[4]: -6
If that's is indeed the case, then the patch I pushed to gh-issue-78-fix
branch should fix the issue.
Fake twelve single file has 10 bytes
Attempting to load just one packet from file
{'negfive': array([-5], dtype=int8),
'negtwelve': array([-6], dtype=int16),
'postwelve': array([12], dtype=int16),
'uintfive': array([2], dtype=uint8)}
Best, Daniel
Totally right on both counts, that'll teach me to do binary conversions by hand late at night! Confirmed that it works on my larger files too. Thank you!
Fixed in #81
For example: the 12 bit signed integer 0x800 returns -30720, or 0x800 - 0x8000. Looks like all integer fields are fit into the nearest numpy size that fits the required bits and sign extension is not working properly?
Example code: