Bitwise Operators (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![yes](media/yes.png)Azure SQL Data Warehouse ![yes](media/yes.png)Parallel Data Warehouse

Bitwise operators perform bit manipulations between two expressions of any of the data types of the integer data type category.
Bitwise operators convert two integer values to binary bits, perform the AND, OR, or NOT operation on each bit, producing a result. Then converts the result to an integer.

For example, the integer 170 converts to binary 1010 1010. The integer 75 converts to binary 0100 1011.

operator bitwise math
AND
If bits at any location are both 1, the result is 1.
1010 1010 = 170
0100 1011 = 75
—————–
0000 1010 = 10
OR
If either bit at any location is 1, the result is 1.
1010 1010 = 170
0100 1011 = 75
—————–
1110 1011 = 235
NOT
Reverses the bit value at every bit location.
1010 1010 = 170
—————–
0101 0101 = 85

See the following topics:
* & (Bitwise AND)
* &= (Bitwise AND Assignment)
* | (Bitwise OR)
* |= (Bitwise OR Assignment)
* [^ (Bitwise Exclusive OR)](../../t-sql/language-elements/bitwise-exclusive-or-transact-sql.md)
* [^= (Bitwise Exclusive OR Assignment)](../../t-sql/language-elements/bitwise-exclusive-or-equals-transact-sql.md)
* ~ (Bitwise NOT)

The operands for bitwise operators can be any one of the data types of the integer or binary string data type categories (except for the image data type), except that both operands cannot be any one of the data types of the binary string data type category. The following table shows the supported operand data types.

Left operand Right operand
binary int, smallint, or tinyint
bit int, smallint, tinyint, or bit
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

See Also

Operators (Transact-SQL)
Data Types (Transact-SQL)
Compound Operators (Transact-SQL)