Not Operator (Visual Basic)
Performs logical negation on a Boolean expression, or bitwise negation on a numeric expression.
For Boolean expressions, the following table illustrates how result is determined.
If expression is
The value of result is
For numeric expressions, the Not operator inverts the bit values of any numeric expression and sets the corresponding bit in result according to the following table.
If bit in expression is
The bit in result is
Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution.
For a Boolean negation, the data type of the result is Boolean. For a bitwise negation, the result data type is the same as that of expression. However, if expression is Decimal, the result is Long.
The Not operator can be overloaded, which means that a class or structure can redefine its behavior when its operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.
The following example uses the Not operator to perform logical negation on a Boolean expression. The result is a Boolean value that represents the reverse of the value of the expression.
The preceding example produces results of False and True, respectively.
The following example uses the Not operator to perform logical negation of the individual bits of a numeric expression. The bit in the result pattern is set to the reverse of the corresponding bit in the operand pattern, including the sign bit.
The preceding example produces results of –11, –9, and –7, respectively.