> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# hex

> Converts a numeric or string value to its hexadecimal representation.

If `x` is a numerical value, this function returns a hexadecimal string representation of the value.

If `x` is a string, this function returns a hexadecimal string representation of the string where each character in the string is converted into two hexadecimal digits.

## Syntax

```Haskell theme={null}
HEX(x);
```

## Parameters

`x`: the string or number to convert. The supported data types are BIGINT, VARCHAR, and VARBINARY (v3.0 and later).

## Return value

Returns a value of the VARCHAR type.

## Examples

```Plain Text theme={null}
mysql> select hex(3);
+--------+
| hex(3) |
+--------+
| 3      |
+--------+
1 row in set (0.00 sec)

mysql> select hex('3');
+----------+
| hex('3') |
+----------+
| 33       |
+----------+
1 row in set (0.00 sec)

mysql> select hex('apple');
+--------------+
| hex('apple') |
+--------------+
| 6170706C65   |
+--------------+

-- The input is a binary value.

mysql> select hex(x'abab');
+-------------+
| hex('ABAB') |
+-------------+
| ABAB        |
+-------------+
1 row in set (0.01 sec)
```

## Keywords

HEX


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.