Go Down

Topic: Signed number grief. (Read 1 time) previous topic - next topic


That's not the mask I wanted.  I wanted this one:
Code: [Select]
const long deviceMask = -(1 << (deviceWordLength - 1));The mask isolates the sign bit for testing, and extends the sign bit when the sign bit is set.  It needs to be as long as the type of the input, which is int in this case, but it doesn't need to be longer.


It should be int, not long, then.
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.


That's not the mask I wanted.

I think you will find that a generic approach is not as optimal as having a series of specific approaches (one for 10-bits, one for 12-bits, etc.) that you can link in for your specific applications.

If those numbers came from an adc module, many allow left-aligned adcs making the shift approach a lot more appealing.

Go Up