HEX | Syntax: | HEX(Integer or 'string') | Return value: | CHAR | Function type: | Conversion function | |
|
|
The HEX() function returns a hexadecimal string of an integer or a string.
For a number, the HEX() function is similar to CONV(number,10,16), floating point numbers are rounded.
If the argument is a string, each byte of each character is converted into two hexadecimal digits.
If the value of the argument is NULL, HEX() returns NULL.
The inverse of HEX() is the UNHEX() function. |
SQL Examples for the HEX function |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
select hex(128);
select hex(15);
select CONV(128,10,16);
select CONV(15,10,16);
select hex(1.2);
select hex(1.6);
select hex('Test');
select hex('128');
SELECT HEX(null);
|
|
hex(128) |
varchar(6) BINARY |
80 |
|
|
hex(15) |
varchar(4) BINARY |
F |
|
|
CONV(128,10,16) |
varchar(64) BINARY |
80 |
|
|
CONV(15,10,16) |
varchar(64) BINARY |
F |
|
|
hex(1.2) |
varchar(8) BINARY |
1 |
|
|
hex(1.6) |
varchar(8) BINARY |
2 |
|
|
hex('Test') |
varchar(8) BINARY |
54657374 |
|
|
hex('128') |
varchar(6) BINARY |
313238 |
|
|
HEX(null) |
varchar(0) BINARY |
NULL |
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the HEX() function in MySQL and MariaDB databases |
The HEX() function in MySQL and MariaDB is used to return a string or numeric value to its hexadecimal representation. The function takes a value as input and returns a string of the characters "0-9" and "a-f" representing the hexadecimal form of that value, for example for use with dealing with binary data, encoding and decoding operations or generating hash values.
The HEX() function converts each individual byte within a string. For strings containing multibyte characters, the hexadecimal representation of each byte is returned, not the entire character. |
|
Further MySQL und MariaDB SQL Conversion functions |
|