How can an (int) be converted to (unsigned int) while preserving the original bit pattern?
问题 Suppose that we define: short x = -1; unsigned short y = (unsigned short) x; According to the C99 standard: Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more 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's complement representation, the bit patterns of these two integers are: x = 1111 1111 1111 1111