Bitwise Operators

I am going to carry one with my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions.

I will exploring the Bitwise Operators today. Every piece of data on a computer is stored as a series of bits, either 1 or 0. Four bits are grouped together to become what is called a nibble. Two nibbles are combined to become a byte. The least significant bits are named lower nibble and the most significant bits are called upper nibble.

The truth tables are the basic foundation of logic gates. These are the gates that go into transistors, the building blocks of computers.

TSQL supports the following three basic bit operations: AND, OR, and XOR. The example below perform bit-wise calculation using each operator.

Here are the logic rules for bit wise operators: the AND operator evaluates to 1 if both bits are 1; the OR operator evaluates to 1 if at least one bit is 1; and the XOR operator evaluates to 1 only if one bit is 1. All other cases evaluate to 0.

The output of each calculation is listed below.

Next time, I will be reviewing the Comparison Operators.

Related posts

Leave a Comment