To continue my current PBP project it looks like I'll need to convert some 'signed' Words (a 16bit signed value read from consecutive bytes of a BMP085 barometric sensors calibration table).
These 'signed' Words are treated as unsigned in PBP when I've read them from the sensor, but I use the S modifier to display them as -ve values on my LCD display.
That was fine, but now I need to really use the true signed value in math operations, so I need to make the unsigned Word into a signed Long.
So here's my hypothetical.
If my Word var contains say the value -14293 in decimal (when Serout2 with SDEC is used to show it), how would I put that value in to a Long variable as signed hex and retain the proper sign of the value (that PBP Words don't care about) ?
I know that I need to read the Words high bit and see if it's a 1 for a negative, then if so set the high bit of the Long to a 1, then copy the remaining bits into the right bits of the long (I think).
I could do bit manipulation byte by byte I guess, but that sounds real messy. Is there a simpler way to have a 'signed' word and expand it into a Long ?
Thanks,
Martin
PS. Actually I think I just thought of a way, but it there might be something better...
Long = Word << 16 'Force the signed word up to the top 16 bits of a Long
Long = Long >> 16 'Shift the Long value back 16 bits right, but PBP keeps the signed bit (high bit) set as required (would it?)
???
Bookmarks