Show me a SIGN
Erlend
Posts: 612
In my application I am reading an integer value from a chip register - in a 24bit/3Byte format. When the value is negative the topmost bit is one (as it should be). I am reading the bits into a LONG and need to make sure the sign is recovered in this (4Byte) format. I believe the ~ (sign extend) operator will only do this when you want to go from BYTE to LONG? Here is how I intend to do this:
Erlend
PRI INT24to32(ptrValue) | value value:= LONG[ptrValue] 'read from ptrValue which is a LONG where b24-31 are unused 0 ' IF value >> 23 & 1 = 1 'check if bit23 is set - means negative number - if negative value:= value | $FF_00_00_00 'extend the sign all the way up to b31 LONG[ptrValue]:= value 'write back to ptrValueIs there a better way?
Erlend
Comments
Erlend