HEX8 returns a character string that is the UTF-8 hexadecimal representation of the storage that contains x.
>>-HEX8(x-+----+-)--------------------------------------------->< '-,z-'
HEX8(x) returns a character string of length 2 * size(x).
HEX8(x,z) returns a character string that contains x with the character z inserted between every set of eight characters in the output string. Its length is 2 * size(x) + ((size(x) - 1)/4).
Under the compiler option USAGE(HEX(CSTG)), the length used in the above calculations is based, for VARYING, VARYING4, and VARYINGZ strings, on cstg(x) rather than on stg(x).
Integer, offset and pointer values will be presented in big endian form.
If the number of bytes to be converted to hex is not known at compile time, then no more than 32767 bytes will be converted.
dcl Sweet char(5) init('Sweet');
dcl Sixteen fixed bin(31) init(16) littleendian;
dcl XSweet char(size(Sweet)*2+(size(Sweet)-1)/4);
dcl XSixteen char(size(Sixteen)*2+(size(Sixteen)-1)/4);
XSweet = hex8(Sweet,'-');
/* '53776565-74'a */
XSweet = heximage8(addr(Sweet),length(Sweet),'-');
/* '53776565-74'a */
XSixteen = hex8(Sixteen,'-');
/* '00000010' - bytes reversed */
XSixteen = heximage8(addr(Sixteen),stg(Sixteen),'-');
/* '10000000' - bytes NOT reversed */
dcl X fixed bin(15) littleendian;
dcl Y fixed bin(15) bigendian;
X = 258; /* stored as '0201'B4 */
Y = 258; /* stored as '0102'B4 */
display (hex8(X)); /* displays 0102 */
display (hex8(Y)); /* displays 0102 */
display (heximage8( addr(X), stg(X) )); /* displays 0201 */
display (heximage8( addr(Y), stg(Y) )); /* displays 0102 */