int x = 100;
In this case ~x is a negative number. When you assigning negative value V to unsigned number, result is equal to maximum possible value for corresponding unsigned data type + 1 - V.Standard wrote: |
---|
4.7.2 If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2^n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ] |