AND, OR, XOR, and NOT - Bitwise Operations in SQL Server

Q

What Are Bitwise Operations in SQL Server Transact-SQL?

✍: FYIcenter.com

A

Bitwise operations are binary operations performed on one or two binary strings. SQL Server supports 4 bitwise operations:

  • & (Bitwise AND) - Performing the single bit Boolean operation "AND" on each bit position.
  • | (Bitwise OR) - Performing the single bit Boolean operation "OR" on each bit position.
  • ^ (Bitwise XOR) - Performing the single bit Boolean operation "XOR" on each bit position.
  • ~ (Bitwise NOT) - Performing the single bit Boolean operation "NOT" on each bit position.

The table below shows you how single bit Boolean operations work:

Input 1:   0   0   1   1
Input 2:   0   1   0   1
        ----------------
& (AND)    0   0   0   1

Input 1:   0   0   1   1
Input 2:   0   1   0   1
        ----------------
| (OR)     0   1   1   1

Input 1:   0   0   1   1
Input 2:   0   1   0   1
        ----------------
^ (XOR)    0   1   1   0

Input 1:   0   0   1   1
        ----------------
~ (NOT)    1   1   0   0

 

Character Strings and Binary Strings in SQL Server Transact-SQL

⇒⇒SQL Server Transact-SQL Tutorials

2017-02-25, 260👍, 0💬