Converts a character string consisting of an even number of hexadecimal digits (0 through 9 and A through F) into a RAW value.

Syntax

HEX-DECODE( expression )
expression
A character expression containing the value you want to convert. If the expression does not contain an even number of hexadecimal digits, or it is the Unknown value (?), the result is the Unknown value (?). If the expression is a zero-length value, the result is a zero-length value.
Note: The BASE64-ENCODE, BASE64-DECODE, HEX-ENCODE, and HEX-DECODE functions do not do any byte ordering. However, the binary output of these functions may be a binary data type such as a MEMPTR or RAW. If the target of these operation’s output is another system where the order of bytes (endianness) differs, you must first normalize the data to what the receiving side is expecting. Otherwise, the results may not be as expected. For example, for a MEMPTR value that you are building yourself, you can use the SET-BYTE-ORDER statement to set the byte order for the MEMPTR variable before you read or write the value.

Example

The following code example illustrates how to use the HEX-DECODE function:

DEFINE VARIABLE memValue AS MEMPTR  NO-UNDO.
DEFINE VARIABLE counter  AS INTEGER NO-UNDO.

memValue = HEX-DECODE("48656C6C6F"). /* "Hello" in hexadecimal */

/* Output the byte values in the MEMPTR returned by HEX-DECODE */
DO counter = 1 TO GET-SIZE(memValue):
    MESSAGE GET-BYTE(memValue, counter).
END.

Running this code displays the numeric byte values contained in the MEMPTR returned by HEX-DECODE, one byte at a time: 72, 101, 108, 108, 111.

See also

HEX-ENCODE function, SET-BYTE-ORDER statement