HEX Function

Purpose

Returns a character string which contains the hexadecimal representation of the variable x.

Syntax

HEX(x,y)

Parameters

x is a variable and y is an expression that must have a nonvarying character type.

Description

HEX returns the hexadecimal representation of the bytes that contain x. Its length is 2 * size(x) when x is the only parameter, i.e. HEX(x). When there is a second parameter, i.e. HEX(x,y), it returns a hexadecimal character string that contains x with y inserted between every set of eight characters. Its length is 2 * size(x) + ((size(x) - 1)/4).

The output character string for the data types Fixed Binary, Pointer, Offset, and Char Varying (applies to the leading 2-byte Fixed Bin size field) will be constructed in big-endian form.

Note: The hexadecimal representation of arrays and structures containing the 4 data types above will be constructed in native format.

The HEX function does not return an exact image of x in storage. If an exact image is required, use the HEXIMAGE built-in function.

Examples

dcl s char (32) varying;

   s = 'The witch cast a terrible spell.';
   
    put skip list (hex(s));
    put skip list (hex(s,'+'));

Will print:

002054686520776974636820636173742061207465727269626C65207370656C6C2E
00205468+65207769+74636820+63617374+20612074+65727269+626C6520+7370656C+6C2E

Restrictions

None.