Demotion of Integers
ANSI 220.127.116.11 The result of converting an integer to a shorter signed integer, or the result of converting an unsigned integer to a signed integer of equal length, if the value cannot be represented
When a long integer is cast to a short, or a short is cast to a
char, the least-significant bytes are retained.
For example, this line
short x = (short)0x12345678L;
assigns the value 0x5678 to
x, and this line
char y = (char)0x1234;
assigns the value 0x34 to
When signed variables are converted to unsigned and vice versa, the bit patterns remain the same. For example, casting -2 (0xFE) to an unsigned value yields 254 (also 0xFE).