Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Discussion options

You must be logged in to vote

Consider your 31.91402 value:

>>> hex(round(31.91402*2048))
'0xff50'

The 16 bit value 0xFF50 is evidently a negative number in two's complement which the code is interpreting as unsigned. To convert a raw 16 bit two's complement number to a signed integer you want:

n = n - 0x10000 if n & 0x8000 else n

Replies: 3 comments 5 replies

Comment options

Josverl
Oct 13, 2025
Collaborator Sponsor

You must be logged in to vote
3 replies
@ujur007
Comment options

@peterhinch
Comment options

Answer selected by ujur007
@ujur007
Comment options

Comment options

You must be logged in to vote
1 reply
@Josverl
Comment options

Josverl Oct 13, 2025
Collaborator Sponsor

Comment options

You must be logged in to vote
1 reply
@ujur007
Comment options

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