Bitwise NOT (~)
The bitwise NOT operator inverts the bit values of any variable and sets the corresponding bit in the result.
Syntax
~ expression
Expression is any valid expression containing the integer data type, which is transformed into a binary number for the bitwise operation.
Values Returned
The bitwise NOT operator returns the reverse of its single operand of the integer data type. All 1’s are converted to 0’s, and all 0’s are converted to 1’s. The bitwise NOT can take only numeric values as its operands.
Examples
The following query performs the complement operation on a numeric literal:
SELECT ~12
The result is -13.
The result is negative because the complement operator complements the sign bit also. This causes Pervasive PSQL to treat the result as a negative number.
The 2's complement of the result number is 13. Therefore, the result is -13.
*Note: The tilde (~) cannot be used as part of a user-defined name.