tohex()
Converts a binary value to a hexadecimal string and returns it.
Syntax
tohex(BLOB_EXPR)
Parameters
BLOB_EXPR- The binary value or expression to convert to a hexadecimal string.
Description
The tohex() function converts binary (byte[]) to a lowercase hexadecimal string and returns it. If the argument is null, returns null. If a non-binary value is passed, returns null. If an array or list is passed, the conversion is applied recursively to each element.
The result always uses lowercase characters (0-9, a-f), and each byte is represented as two hexadecimal digits.
Error codes
N/A
Usage examples
-
Converting a string to binary and encoding it as hexadecimal
json "{'val': 'hello'}" | eval result = tohex(binary(val)) | # result: "68656c6c6f" -
Non-binary value input
json "{'val': 1234}" | eval result = tohex(val) | # result: null -
NULL input
json "{'val': null}" | eval result = tohex(val) | # result: null
Compatibility
The tohex() function has been available since before Sonar 4.0.