Share via


Bitwise NOT Operator (~)

Performs a bitwise NOT (negation) on an expression.

~ expression

Arguments

  • expression
    Any numeric expression.

Remarks

The ~ operator looks at the binary representation of the values of the expression and does a bitwise negation operation on it.

Any digit that is a 1 in the expression becomes a 0 in the result. Any digit that is a 0 in the expression becomes a 1 in the result.

When the ~ operator acts on an operand of an integral data type, it performs no coercion and returns a value of the same data type as the operand. When the operand is of a non-integral data type, the value is coerced to type int before the operation is performed, and the return value of the operator is of type int.

The following example illustrates use of the bitwise NOT (~) operator.

var temp = ~5;

The resulting value is -6, as shown in the following table.

Expression

Binary value (two's complement)

Decimal value

5

00000000 00000000 00000000 00000101

5

~5

11111111 11111111 11111111 11111010

-6

Requirements

Version 1

See Also

Reference

Logical NOT Operator (!)

Concepts

Operator Precedence

Operator Summary