MySQL | HEX method
Start your free 7-days trial now!
MySQL's HEX(~)
method returns a hexadecimal representation of the input argument.
Hexadecimal is base 16, where there are 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. A through F in hexadecimal is 10 through 15 in decimal notation.
Parameters
1. str or N
| string or number
The string or number to return hexadecimal string representation for.
Return value
Input | Return value |
---|---|
String | each byte of each character in the string is converted to two hexadecimal digits. |
Number | representation of the number converted to base 16. This is equivalent to |
Examples
String argument
To return hexadecimal representation of 'Apple'
:
SELECT HEX('Apple');
+--------------+| HEX('Apple') |+--------------+| 4170706C65 |+--------------+
Note that 'A'
has the byte value of 65
. In hexadecimal we can see this is represented as '41'
.
Numeric argument
To verify that HEX(30)
and CONV(30, 10, 16)
are equivalent:
SELECT HEX(30), CONV(30, 10, 16);
+---------+------------------+| HEX(30) | CONV(30, 10, 16) |+---------+------------------+| 1E | 1E |+---------+------------------+