Binary String Bit-Operation Examples The  CAST(... AS BINARY(16))  function is used here because the masks must be the same length as the UUID value against which they are applied. The same result can be produced using other functions to pad the masks to the required length: Use the masks to extract the timestamp and node number parts: The preceding example uses these bit operations: right shift ( >> ) and bitwise AND ( & ). UUID_TO_BIN()  takes a flag that causes some bit rearrangement in the resulting binary UUID value. If you use that flag, modify the extraction masks accordingly. The next example uses bit operations to extract the network and host parts of an IPv6 address. Suppose that the network part has a length of 80 bits. Then the host part has a length of 128  − 80 = 48 bits. To extract the network and host parts of the address, convert it to a binary string, then use bit operations in binary-string context. Convert the text IPv6 address to the corresponding binary string: Define the network length in bits: Construct network and host masks by shifting the all-ones address left or right. To do this, begin with the address  :: , which is shorthand for all zeros, as you can see by converting it to a binary string like this: To produce the complementary value (all ones), use the  ~  operator to invert the bits: Shift the all-ones value left or right to produce the network and host masks: mysql>  SELECT HEX(~INET6_ATON(’::’)) AS ’all ones’; +----------------------------------+ | all ones | +----------------------------------+ | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF | +----------------------------------+ mysql>  SELECT HEX(INET6_ATON(’::’)) AS ’all zeros’; +----------------------------------+ | all zeros | +----------------------------------+ | 00000000000000000000000000000000 | +----------------------------------+ mysql>  SET @ip = INET6_ATON(’fe80::219:d1ff:fe91:1a72’); mysql>  SET @net_len = 80; mysql>  SELECT HEX(@uuid & @ts_mask) AS ’timestamp part’; +----------------------------------+ | timestamp part | +----------------------------------+ | 6CCD780CBABA10260000000000000000 | +----------------------------------+ mysql>  SELECT HEX(@uuid & @node_mask) AS ’node part’; +----------------------------------+ | node part | +----------------------------------+ | 000000000000000000005B8C656024DB | +----------------------------------+ SET @ts_mask= RPAD(X’FFFFFFFFFFFFFFFF’ , 16, X’00’); SET @node_mask = LPAD(X’FFFFFFFFFFFF’, 16, X’00’) ; Note 2263