I'm working through K&R to learn C, and I've reached the bit on bitwise operators. I stumbled onto this issue whilst trying to accomplish something else, and have been trying to understand what's going on ever since.

Here's two bits of code. They both output the same numbers by doing left-shift bitwise operations, starting from ~0

The first method, however, shifts to zero from -2147483648; while the second method shifts to -1 from the same number. And I don't understand why.

Code:

int main(void)
{
int i = ~0;
int j = 0;
while (j != 33) {
i <<= 1;
printf("%d: %d\n", j++, i);
}
return 0;
}

Code:

int main(void)
{
int i = 0;
while (i < 33)
printf("%d: %d\n", i, (~0 << i++));
return 0;
}

Any clarification would be appreciated!