Bitwise Operators

Accessing and Changing Relational Data

Accessing and Changing Relational Data

Bitwise Operators

Bitwise operators are used on int, smallint, or tinyint data. The ~ (Bitwise NOT) operator can also use bit data. All bitwise operators perform an operation on the one or more specified integer values as translated to binary expressions within Transact-SQL statements. For example, the ~ (Bitwise NOT) operator changes binary 1s to 0s and 0s to 1s. To check bitwise operations, you can convert or calculate decimal values.

For example, you want to add 150 and 75 together, but you're interested in not only the decimal value of 225, but want to use binary arithmetic (addition of 0s and 1s). Use the bitwise AND operator (&) for this purpose.

If you are storing integer data (normal decimal values like the 150 and 75 mentioned earlier) and want to perform internal translation to do binary math, use bitwise operators. Bitwise operators are also valuable to get a NOT value which is not necessarily the exact opposite.

See Also

& (Bitwise AND)

~ (Bitwise NOT)

| (Bitwise OR)

^ (Bitwise Exclusive OR)

Data Types