Bitwise operators perform mathematical operations between integer values as translated to binary expressions within Transact-SQL statements. All the bitwise operators translate the integer parameters into binary representation before evaluating them.
These are the bitwise operators:
| Symbol | Meaning | Can be used on |
|---|---|---|
| & | Bitwise AND (two operands) | int, smallint, or tinyint columns only |
| | | Bitwise OR (two operands) | int, smallint, or tinyint columns only |
| ^ | Bitwise exclusive OR (two operands) | int, smallint, or tinyint columns only |
| ~ | Bitwise NOT (one operand) | int, smallint, tinyint, or bit columns only |
The bitwise operators that require two operands (&, |, and ^) can be used on columns with these datatypes:
| Left operand |
Right operand |
|---|---|
| int | int, smallint, tinyint, binary, or varbinary |
| smallint | int, smallint, tinyint, binary, or varbinary |
| tinyint | int, smallint, tinyint, binary, or varbinary |
| varbinary | int, smallint, or tinyint |
| bit | int, smallint, tinyint, or bit |
| float (and real) | none |
| binary | int, smallint, or tinyint |