Reading 9 bit 2's complement integer

Thread Starter

AlbertHall

Joined Jun 4, 2014
10,558
I am trying to read a 2's complement 9 bit integer (PS2 mouse). The code below generates an 'arithmetic overflow' warning on "x |= 0xFF00;" What is the correct way to do this, please?
Code:
int16_t x;
bool sign;
x = ReadByte(PS2);    // The lower 8 bits
sign = ReadSign(PS2);
if (sign)     // if value is negative
{
    x |= 0xFF00;   // Attempt to set high byte to all 1's
}
 

JohnInTX

Joined Jun 26, 2012
4,344
Try uint16_t x; ?
The OR should be valid. If you can't fix it normally and you've verified that it is ok:

C:
#pragma warning push
#pragma warning disable (the message number reported)
  x |= 0xFF00;
#pragma warning pop
 
Last edited:
Top