This topic describes the bit functions that are supported by PolarDB-X.

Bit functions are classified into two types: scalar function and aggregate function.

Scalar functions supported by PolarDB-X

Function Description
| The bitwise OR operator.
^ The bitwise exclusive OR (XOR) operator.
& The bitwise AND operator.
BIT_COUNT() Returns the number of 1s in the binary representation of a number.

Aggregate functions supported by PolarDB-X

Function Description
BIT_OR() The bitwise OR operator.
BIT_XOR() The bitwise XOR operator.
BIT_AND() The bitwise AND operator.

Example

The function returns the number of 1s in the binary representation of a number. The function returns NULL if the argument of the function is NULL.

mysql> SELECT BIT_COUNT(29), BIT_COUNT(b'101010');
+--------------+----------------------+
| BIT_COUNT(29) | BIT_COUNT(b'101010') |
+--------------+----------------------+
|            4 |                    3 |
+--------------+----------------------+
1 row in set (0.00 sec)

mysql> SELECT BIT_COUNT(NULL);
+-----------------+
| BIT_COUNT(NULL) |
+-----------------+
|            NULL |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT 3 & 2;
+-------+
| 3 & 2 |
+-------+
|     2 |
+-------+
1 row in set (0.01 sec)