HEX() FUNCTION in MySQL

HEX() FUNCTION
The MySQL HEX function is used to get a hexadecimal string for the specified string.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
HEX( string )
HEX( string )
HEX( string )

Parameters:
string: It is used to specify the string to evaluate.

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT HEX ( ‘A’ );
mysql> SELECT HEX ( ‘A’ );
mysql> SELECT HEX ( ‘A’ );

Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
41
41
41

Explanation:
The hex code of the string is returned.

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT HEX ( 1 );
mysql> SELECT HEX ( 1 );
mysql> SELECT HEX ( 1 );

Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
31
31
31

Explanation:
The hex code of the number is returned.