content_image/829259.jpg content_image/829260.jpg content_image/829252.jpg content_image/829253.jpg content_image/829251.jpg
mysql> SET @net_mask = ~INET6_ATON(’::’) << (128 - @net_len); mysql> SET @host_mask = ~INET6_ATON(’::’) >> @net_len; 

Display the masks to verify that they cover the correct parts of the address: 

mysql> SELECT INET6_NTOA(@net_mask) AS ’network mask’; 

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

mysql> SELECT INET6_NTOA(@host_mask) AS ’host mask’; 

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

Extract and display the network and host parts of the address: 

mysql> SET @net_part = @ip & @net_mask; mysql> SET @host_part = @ip & @host_mask; mysql> SELECT INET6_NTOA(@net_part) AS ’network part’; 

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

mysql> SELECT INET6_NTOA(@host_part) AS ’host part’; 

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

The preceding example uses these bit operations: Complement ( ~ ), left shift ( << ), and bitwise AND ( & ). 

The remaining discussion provides details on argument handling for each group of bit operations, more information about literal-value handling in bit operations, and potential incompatibilities between MySQL 8.0 and older MySQL versions. 

## Bitwise AND, OR, and XOR Operations 

For & , | , and ^  bit operations, 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. 

Examples of numeric evaluation: 

mysql> SELECT 64 | 1, X’40’ | X’01’; 

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

