The one’s complement operator (~), sometimes called the “bitwise complement” operator, yields a bitwise one’s complement of its operand. That is, every bit that is set in the operand is 0 in the result. Conversely, every bit that is 0 in the operand is set in the result. The operand to the one’s complement operator must be an integral type.
unsigned short y = 0xAAAA;
y = ~y;
In this example, the new value assigned to y
is the one’s complement of the unsigned value 0xAAAA, or 0x5555.
Integral promotion is performed on integral operands, and the resultant type is the type to which the operand is promoted. See Integral Promotions for more information on how the promotion is done.