Bitwise Functions

BIT_COUNT

BIT_COUNT(x, bits) Count the number of bits set in x (treated as bits-bit signed integer) in 2’s complement representation.

SQL commandResult
SELECT BIT_COUNT(15, 4)4
  • 15 = '1111' in binary *

BITWISE_AND

BITWISE_AND(x, y) Returns the bitwise AND of x and y in 2’s complement representation.

-- 10101 & 111 = 101
SELECT BITWISE_AND(37, 7)
5

BITWISE_OR

BITWISE_OR(x, y) Returns the bitwise OR of x and y in 2’s complement representation.

-- 10001 | 111 = 10111
SELECT BITWISE_OR(33, 7)
39

BITWISE_NOT

BITWISE_NOT(x) Returns the bitwise NOT of x in 2’s complement representation.

SQL commandResult
SELECT BITWISE_NOT(4)-5

BITWISE_XOR

BITWISE_XOR(x, y) Returns the bitwise XOR of x and y in 2’s complement representation.

SQL commandResult
SELECT BITWISE_XOR(21, 10)31

10101 | 01010 = 11111