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

Int24 incorrect for big-endianness #330

Closed
paamand opened this issue Jan 7, 2022 · 2 comments
Closed

Int24 incorrect for big-endianness #330

paamand opened this issue Jan 7, 2022 · 2 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@paamand
Copy link
Contributor

paamand commented Jan 7, 2022

The byte-order is interpreted wrong for big-endian int24 and uint24.
When reading the sequence "80 00 80" the correct interpretation is given for little endian (i.e. -8388480 for int24, 8388736 for uint24) but wrong numbers are given for big endian (-32768 for int24, 8421376 for uint24).

The interpretation mixes up the two last bytes. I.e 8421376 is "80 80 00" instead of the input "80 00 80".

The problem is line 144 to 148 of /media/data_inspector/byteData.ts

@lramos15
Copy link
Member

@paamand Thanks for the bug report and code pointer. If you want to create a PR to fix this problem let me know, otherwise I can go ahead and fix it.

@lramos15 lramos15 added the bug Issue identified by VS Code Team member as probable bug label Jan 10, 2022
paamand added a commit to paamand/vscode-hexeditor that referenced this issue Jan 10, 2022
Making explicit endian indexing of the adjacent bytes and explicit signed conversion.
@paamand
Copy link
Contributor Author

paamand commented Jan 10, 2022

Done. #331
I have no prior experience with vscode extensions nor the language used. So syntax is purely inferred from the other code.
A python equivalent would be:

def read24(b, little, signed):
    y = b[2]<<16 | b[1]<<8 | b[0] if little else b[0]<<16 | b[1]<<8 | b[2]
    if signed and y >= 1<<23: y -= 1<<24
    return y

Please review before merging ;)
//R

lramos15 pushed a commit that referenced this issue Jan 11, 2022
Making explicit endian indexing of the adjacent bytes and explicit signed conversion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants