content_image/818444.jpg content_image/818445.jpg content_image/818446.jpg content_image/818455.jpg content_image/818456.jpg
mysql> SET @v2 = b’1100001’+0; mysql> SET @v3 = CAST(b’1100001’ AS UNSIGNED); mysql> SELECT @v1, @v2, @v3; 

<img src='content_image/818444.jpg'>

An empty bit value ( b’’ ) evaluates to a zero-length binary string. Converted to a number, it produces 0: 

mysql> SELECT CHARSET(b’’), LENGTH(b’’); 

<img src='content_image/818445.jpg'>

mysql> SELECT b’’+0; 

<img src='content_image/818446.jpg'>

Bit-value notation is convenient for specifying values to be assigned to BIT  columns: 

mysql> CREATE TABLE t (b BIT(8)); mysql> INSERT INTO t SET b = b’11111111’; mysql> INSERT INTO t SET b = b’1010’; mysql> INSERT INTO t SET b = b’0101’; 

Bit values in result sets are returned as binary values, which may not display well. To convert a bit value to printable form, use it in numeric context or use a conversion function such as BIN()  or HEX() . High-order 0 digits are not displayed in the converted value. 

mysql> SELECT b+0, BIN(b), OCT(b), HEX(b) FROM t; 

<img src='content_image/818455.jpg'>

For bit literals, bit operations are considered numeric context, but bit operations permit numeric or binary string arguments in MySQL 8.0 and higher. To explicitly specify binary string context for bit literals, use a _binary  introducer for at least one of the arguments: 

mysql> SET @v1 = b’000010101’ | b’000101010’; mysql> SET @v2 = _binary b’000010101’ | _binary b’000101010’; mysql> SELECT HEX(@v1), HEX(@v2); 

<img src='content_image/818456.jpg'>

The displayed result appears similar for both bit operations, but the result without _binary  is a BIGINT value, whereas the result with _binary  is a binary string. Due to the difference in result types, the displayed values differ: High-order 0 digits are not displayed for the numeric result. 

## 9.1.6 Boolean Literals 

