Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
ANSI 3.2.1.2 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 y
.
When signed
variables are converted to unsigned
and vice-versa, the bit patterns remain the same. For example, casting -2 (0xFFFFFFFE) to an unsigned int
value yields 4294967294 (also 0xFFFFFFFE).