Suppose we define:
short x = -1;
unsigned short y = (unsigned short) x;
In accordance with standard C99:
Otherwise, if the new type is unsigned, the value is converted to repeatedly adding or subtracting one greater than the maximum value that can be represented in the new type until the value is in the range of the new type. (ISO / IEC 9899: 1999 6.3.1.3/2)
So, assuming two bytes for short and a two-component representation, the bit patterns of these two integers are:
x = 1111 1111 1111 1111 (value of -1),
y = 1111 1111 1111 1111 (value of 65535).
-1 short, , , 65535, 65536 - 1, 65535, . , int , .
, , . " ,..." (ISO/IEC 9899: 1999 6.2.6.2/2)
, , x 1111 1111 1111 1110 , , , x 1000 0000 0000 0001. -1, short, 65536, . 1111 1111 1111 1111.
, int unsigned int .
, int unsigned int, -, , . , , .
, - ? , int ? , int unsigned int?
, int unsigned int , - . , int int N _t :
unsigned short y = (unsigned short)(int16_t) x;
, , ! , , - . , int unsigned int, , @Leushenko . , , .