Skip to main content
Version: V1.0.0

BIT_XOR

Declaration

BIT_XOR(expr)

Description

Returns the bitwise XOR of all bits in expr.

The result type depends on whether the function arguments are evaluated as binary strings or numbers. If the argument values are binary strings and not hexadecimal literals, bit literals, or NULL literals, the binary string evaluation occurs. Otherwise, numeric computation occurs, and the argument values are converted to unsigned 64-bit integers when necessary.

If no matching rows are found, BIT_XOR() returns a neutral value with the same length as the argument value (all bits set to 0).

Unless all values are NULL, NULL values do not affect the result. In this case, the result is a neutral value with the same length as the argument value.

Examples

SELECT year,month,BIT_COUNT(BIT_XOR(1<<day)) AS days FROM tbl1 GROUP BY year,month;
+------+-------+------+
| year | month | days |
+------+-------+------+
| 2021 | 01 | 3 |
| 2021 | 02 | 1 |
+------+-------+------+
2 rows in set (0.001 sec)