Bit Functions and Operators

TiDB supports all of the bit functions and operators available in MySQL 8.0.

Bit functions and operators:

NameDescription
BIT_COUNT()Return the number of bits that are set as 1
&Bitwise AND
~Bitwise inversion
|Bitwise OR
^Bitwise XOR
<<Left shift
>>Right shift

MySQL compatibility

There are some differences between MySQL 8.0 and earlier versions of MySQL in handling bit functions and operators. TiDB aims to follow the behavior of MySQL 8.0.

Known issues

In the following cases, the query results in TiDB are the same as MySQL 5.7 but different from MySQL 8.0.

  • Bitwise operations with binary arguments. For more information, see #30637.
  • The result of the BIT_COUNT() function. For more information, see #44621.