Python - bit manipulation and decoding signed value in 2's complement

Status
You're currently viewing only stodge's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

stodge

Ars Tribunus Militum
1,907
I seem to be having a brain fart today as my mind is just blank. I'm parsing datagrams to extract some data. I have an x,y coordinate pair in 8 bytes. My ICD tells me:

bytes 1-4 are the X position
bytes 5-8 are the Y position

The 64th bit of the X position is the sign bit, so it's in 2's complement. The 32nd bit is the sign bit for the Y position.

So to decode the X coordinate, do I reverse the top four bytes:

ABCD ==> DCBA

And then the sign bit is the 8th bit of the first byte (A)?

*whacks head against wall*
 
Status
You're currently viewing only stodge's posts. Click here to go back to viewing the entire thread.
Not open for further replies.