MySQL HEX() Function
In MySQL, the HEX() function returns a string that represents the hexadecimal value of the given number or string.
The UNHEX() function is the reverse operation of the HEX()function.
HEX() Syntax
Here is the syntax of MySQL HEX() function:
HEX(number)
HEX(string)
Parameters
number/string- Required. A number or a string.
Return value
The HEX() function returns a string that represents the hexadecimal value of the given number or string.
- If
number/stringis a number, the function will returns the hexadecimal value of it. - If
number/stringis a string, the function converts each character to 2 hexadecimal characters. - If
number/stringisNULL, the function will returnsNULL.
HEX() Examples
SELECT
HEX(16),
HEX(255),
HEX('a'),
HEX('b'),
HEX('c'),
HEX('abc'),
HEX(NULL)\G
HEX(16): 10
HEX(255): FF
HEX('a'): 61
HEX('b'): 62
HEX('c'): 63
HEX('abc'): 616263
HEX(NULL): NULL