Binary String Bit-Operation Examples mysql>  SELECT _binary X’0040’ | X’0001’; +---------------------------+ | _binary X’0040’ | X’0001’ | +---------------------------+ | A | +---------------------------+ mysql>  SELECT _binary X’40’ | X’01’; +-----------------------+ | _binary X’40’ | X’01’ | +-----------------------+ | A | +-----------------------+ mysql>  SELECT LPAD(X’40’, 2, X’00’) | X’0001’; +---------------------------------+ | LPAD(X’40’, 2, X’00’) | X’0001’ | +---------------------------------+ | A | +---------------------------------+ mysql>  SELECT X’40’ | SUBSTR(X’0001’, 2, 1); +-------------------------------+ | X’40’ | SUBSTR(X’0001’, 2, 1) | +-------------------------------+ | A | +-------------------------------+ mysql>  SET @uuid = UUID_TO_BIN(’6ccd780c-baba-1026-9564-5b8c656024db’); mysql>  SELECT HEX(@uuid); +----------------------------------+ | HEX(@uuid) | +----------------------------------+ | 6CCD780CBABA102695645B8C656024DB | +----------------------------------+ mysql>  SET @ts_mask = CAST(X’FFFFFFFFFFFFFFFF’ AS BINARY(16)); mysql>  SET @node_mask = CAST(X’FFFFFFFFFFFF’ AS BINARY(16)) >> 80; mysql>  SELECT HEX(@ts_mask); +----------------------------------+ | HEX(@ts_mask) | +----------------------------------+ | FFFFFFFFFFFFFFFF0000000000000000 | +----------------------------------+ mysql>  SELECT HEX(@node_mask); +----------------------------------+ | HEX(@node_mask) | +----------------------------------+ | 00000000000000000000FFFFFFFFFFFF | +----------------------------------+ 2262 Construct bitmasks for the timestamp and node number parts of the value. The timestamp comprises the first three parts (64 bits, bits 0 to 63) and the node number is the last part (48 bits, bits 80 to 127): The following example illustrates use of bit operations to extract parts of a UUID value, in this case, the timestamp and IEEE 802 node number. This technique requires bitmasks for each extracted part. Convert the text UUID to the corresponding 16-byte binary value so that it can be manipulated using bit operations in binary-string context: Padding or stripping can also be accomplished using functions such as  LPAD() ,  RPAD() ,  SUBSTR() , or  CAST() . In such cases, the expression arguments are no longer all literals and  _binary  becomes unnecessary. Examples: Binary String Bit-Operation Examples