Bitwise operators
Bitwise operators perform bitwise operations between two expressions. These two expressions can be any two integer data types. Symbols of bitwise operators and their definitions are as follows:4.3.
Table4.3Bitwise operators
Operator |
IncludingYi |
& ( by bit and) |
bitwise AND ( two operands ) |
| ( by bit or) |
bitwise OR ( two operands ) |
^ ( bitwise mutex or) |
bitwise OR ( two operands ) |
~ (By bitNot) |
Bitwise Inversion(One operand) |
Bitwise operators can be any data type in integer or binary string data types.(HoweverImageExcept for Data Types)In addition, the two operands cannot be a data type of the binary string data type at the same time.
Case: reverse the following sex field. Another method is case when... end.
Declare @ TB table (sex bit, num2 INT) insert into @ TB Select Insert into @ TB select Insert into @ TB select sex, '~ Sex inverse '= ~ Sex, 'sex ^ '= sex ^ 1, num2 from @ TB