HEX()

Description

For a string argument str, HEX() returns a hexadecimal string representation of str where each byte of each character in str is converted to two hexadecimal digits. (Multibyte characters therefore become more than two digits.)

For a numeric argument N, HEX() returns a hexadecimal string representation of the value of N treated as an integer number. This is equivalent to CONV(N,10,16). The inverse of this operation is performed by CONV(HEX(N),16,10).

For a NULL argument, this function returns NULL.

Syntax

  1. > HEX(str), HEX(N)

Arguments

ArgumentsDescription
NRequired. A number which is to be converted to hexadecimal.
strRequired. A string whose each character is to be converted to two hexadecimal digits.

Examples

  1. > SELECT HEX('abc');
  2. +----------+
  3. | hex(abc) |
  4. +----------+
  5. | 616263 |
  6. +----------+
  7. 1 row in set (0.00 sec)
  8. > SELECT HEX(255);
  9. +----------+
  10. | hex(255) |
  11. +----------+
  12. | FF |
  13. +----------+
  14. 1 row in set (0.00 sec)