Posted By:
Benedito_Santos
Posted On:
Tuesday, August 30, 2011 03:43 PM
I am reading byte b, where each bit has to be evaluated.
I am checking each bit with b & 0x80, b & 0x40, etc, until b & 0x01.
My problem happens with bytes larger than 0x80, which result in a weird negative number.
For instance, byte b = 0x80 (that is -128) results in an integer equal to -84. My byte, containing 0x80, results in a binary 1010 1100, not the expected 1000 0000.
Is there any way to get the correct bit configuration? My solution works for all cases, except when bit 0 is set.
Thanks for any help!