tempInt16 := Int16((byte1 shl 8) + byte2);
200*256+255=51455, which is greater than 32767
Quote from: y.ivanov on April 15, 2021, 05:42:48 pm200*256+255=51455, which is greater than 32767 But this is what I don't understand. 200 > 127, so the sign bit is 1. Thus, as the two bytes represent a signed int, I should get a negative value: -14081But my clarification that the two bytes represent a signed, not an unsigned int is ignored.
type Tbytes2int16 = packed record case integer of 0: (byte2, byte1 : Byte); 1: (tempInt16 : Int16); end;
But beware of endianness issues.
When byte1 is greater than 127 (decimal) the expressionCode: Pascal [Select][+][-](byte1 shl 8)is too large to fit in a signed 16 bit integer, and so the compiler warns you of that fact if range checks are enabled.It is as simple as that.