Categories: MySQL FunctionsPHP

MySQL8 HEX() Functions – String Functions

MySQL HEX() Functions: Syntax

HEX ( string1 );
or
HEX ( N );
string1 represents input as a string.
N represents input as a number.

MySQL HEX() Functions: Description

Hex() function returns a hexadecimal representation of decimal or string value.

    • If the argument is a string argument then, HEX() function returns a hexadecimal string representation of string1 where each byte of each character in string1 is converted to two hexadecimal digits. (Multibyte characters, therefore, become more than two digits.)
    • We can use the UNHEX() function to inverse the original value converted by HEX() function. This will work for string arguments.
    • If the argument is a numeric argument then, Hex() function returns a hexadecimal string representation of the value of N treated as a longlong (BIGINT) number. This is equivalent to CONV(HEX(N),16,10). The inverse of this operation is performed by CONV(HEX(N),16,10).

MySQL HEX() Functions: Parameter

[table caption=”” width=”100%” colwidth=”15%|30%|55%” colalign=”left|left|left”]
Name, Required /Optional, Description
string1, Required, It represents input as a string.
N, Numeric, It represents input as a number.

[/table]


MySQL HEX() Functions: Output

[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Returns, hexadecimal representation of decimal or string value.
[/table]


MySQL HEX() Functions: Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 5.7
[/table]


MySQL HEX() Functions: Example 1

mysql> SELECT HEX(200);
+----------+
| HEX(200) |
+----------+
| C8       |
+----------+
1 row in set (0.00 sec)

MySQL HEX() Functions: Example 2

Shows string as input.

mysql>  SELECT X'74757473', HEX('tuts'), UNHEX(HEX('tuts'));
+-------------+-------------+--------------------+
| X'74757473' | HEX('tuts') | UNHEX(HEX('tuts')) |
+-------------+-------------+--------------------+
| tuts        | 74757473    | tuts               |
+-------------+-------------+--------------------+
1 row in set (0.00 sec)

MySQL HEX() Functions: Example 3

Shows numbers as input. As, u can see in this example, UNHEX() doesn’t inverse HEX() numeric values.

mysql> SELECT HEX(155), CONV(HEX(155),16,10) , unhex(hex(155));
+----------+----------------------+-----------------+
| HEX(155) | CONV(HEX(155),16,10) | unhex(hex(155)) |
+----------+----------------------+-----------------+
| 9B       | 155                  | �                |
+----------+----------------------+-----------------+
1 row in set (0.00 sec)

See all MySQL String functions MySQL 8 String Functions.


Related articles : UNHEX(), CONCAT(), CONCAT_WS() , LOWER(), UPPER(), LTRIM(), RTRIM().


PHP Related articles : HEX2BIN(), BIN2HEX(), PHP STRING FUNCTIONS().

jyoti rani

Recent Posts

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

2 days ago

Confused About Where to Buy Toys in India for your little one? We’ve Got You Covered

Looking for the perfect toy for your child can feel overwhelming with so many choices in today’s market. Whether you're…

3 days ago

A New Age of Play: Exploring the Magic of a Toy Shop in Delhi

In the heart of every child lies a world bursting with imagination — and the key to unlocking that world…

4 days ago

Creating Smiles with Play: The Magic of a Toy Store in Noida

In the fast-paced world of growing cities and digital lifestyles, children need spaces where their imagination is free to roam.…

5 days ago

A World of Wonder: Inside the Most Delightful Toy Store in Delhi

In a city as vibrant and diverse as Delhi, there’s a magic that lives beyond the monuments, food stalls, and…

6 days ago

The Magic of Play: Exploring the Best Toy Shop in Noida and Beyond

In the vibrant and rapidly developing city of Noida, playtime is getting smarter, more imaginative, and more inclusive than ever…

1 week ago