K&R A6.2 says the following:
"Any integer is converted to a given unsigned type by finding the smallest non-negative value that is congruent to that integer, modulo one more than the largest value that can be represented in the unsigned type. In a two's complement representation, this is equivalent to left-truncation if the bit pattern of the unsigned type is narrower, and to zero-filling unsigned values and sign-extending signed values if the unsigned type is wider."
How does the second sentence follow from the first for negative numbers? More specifically, how do you determine the smallest non-negative value congruent to a given negative number?
For example if you have
what is going to happen exactly?Code:char c = -1; unsigned int i = c;
In a two's complement representation, c will have the bit pattern 1111 1111, and so according to sentence 2, i will have the bit pattern 1111 ... 1111 (= (2**32) - 1) for sizeof(int) == 4.
How would you get this result by the method of the first sentence? Presumably (2**32)-1 is the smallest non-negative value that is congruent to -1, modulo 2**32. But why is that the case?