Not sure where this goes. It directly applies to Tiny25/45/85 so, I am starting here, even though the real question has to do with signed integer behavior.
This is an application running in a Tiny25/45. I am using the 20X amplifier as one of the ADC inputs. Since the potential offset is large enough, I am measuring the offset by shorting the differential inputs (internally, using one of the channel selections) and measuring using Differential Bipolar mode. I've posted a couple of other questions about this recently, if anyone wants the back story (its not very juicy).
The spec sheet says the following about the result:
The result is presented in two's complement form, from 0x200 (-512d) through 0x000 (+0d) to 0x1FF (+511d).
It appears that using this signed 10-bit value arithmetically, I need to convert the format of negative values into a proper 16-bit signed number. It appears to me that this requires extending the high bits of negative values.The process I am considering looks like this (abbreviated:
int16_t result = ADC; if (result & 0x0200) result |= 0xfc00; //set high 6 bits
My question is this: do the bitwise operators "care" whether the value being operated on is signed or unsigned?
While speed is not much of an issue (this happens only during bootup and I have close to 100ms to do this 16 times!), I do wonder whether or not it would be better (by some objective measure) to make result part of a union and operate only on the high byte. It would certainly make the code more obscure while maybe reducing execution time .
Thanks for your input and insight -