1. ## Integral Conversions

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

Code:
```char c = -1;
unsigned int i = c;```
what is going to happen exactly?

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?

Any ideas?

2. all the modulo sentence is about putting wider type inside type with less bits...

for example if you write

unsigned char u = x;

value of x will be shortened by %256 (255 is biggest value represented by unsigned char)

3. Are you sure about that? The way I read it, the whole of the second sentence (including the part about converting narrower types to wider types) relates to the first sentence.

4. modulo - is about left-truncating... when you zero or sign filling - your modulo operator does nothing - returning same number