Bitwise negation operator ~

The ~ (bitwise negation) operator yields the bitwise complement of the operand. In the binary representation of the result, every bit has the opposite value of the same bit in the binary representation of the operand. The operand must have an integral type. The result has the same type as the operand but is not an lvalue.

Suppose x represents the decimal value 5. The 16-bit binary representation of x is:

0000000000000101

The expression ~x yields the following result (represented here as a 16-bit binary number):

1111111111111010

Note that the ~ character can be represented by the trigraph ??-.

The 16-bit binary representation of ~0 is:

1111111111111111
IBM extension

The bitwise negation operator has been extended to handle complex types. With a complex type, the operator computes the complex conjugate of the operand by reversing the sign of the imaginary part.

End of IBM extension

Related information