&

Description

Bitwise AND operator returns an unsigned 64-bit integer.

The result type depends on whether the arguments are evaluated as binary strings or numbers:

  • Binary-string evaluation occurs when the arguments have a binary string type, and at least one of them is not a hexadecimal literal, bit literal, or NULL literal. Numeric evaluation occurs otherwise, with argument conversion to unsigned 64-bit integers as necessary.
  • Binary-string evaluation produces a binary string of the same length as the arguments. If the arguments have unequal lengths, an ER_INVALID_BITWISE_OPERANDS_SIZE error occurs. Numeric evaluation produces an unsigned 64-bit integer.

Syntax

1. > SELECT value1 & value2;

Examples

1. mysql> SELECT 29 & 15;
2. +---------+
3. | 29 & 15 |
4. +---------+
5. |      13 |
6. +---------+
7. 1 row in set (0.06 sec)

9. CREATE TABLE bitwise (a_int_value INT NOT NULL,b_int_value INT NOT NULL);
10. INSERT bitwise VALUES (170, 75);

12. mysql> SELECT a_int_value & b_int_value FROM bitwise;
13. +---------------------------+
14. | a_int_value & b_int_value |
15. +---------------------------+
16. |                        10 |
17. +---------------------------+
18. 1 row in set (0.02 sec)