Bytes are neither positive nor negative in themselves: they are a pure eight bit value and it's only when you convert them to an integer that they "Acquire" a sign (or strictly speaking any "numeric value" at all).

When you call ReadByte it returns a 32 bit integer which contains the byte value as it' least significant bits; all the others are zero, which means a positive value for an integer - a negative integer has the top bits set so a hex value of FFFFFFFF is minus one, FFFFFFFE is minus two, and so on.

If your Arduino is returning a byte value which uses the same scheme so FF is minus one, FE is minus two, ... then you will need to extend the "sign bit" through the rest of the integer value to get your "real number".

I'd probably do it by checking bit 7 of the integer, and using a binary OR to add FFFFFF00 to the value if it was set.

15,507,266 members