Converting to hexadecimal or bit data (HEX-OF, BIT-OF)

You can use the HEX-OF or BIT-OF intrinsic functions to convert data of any type to hexadecimal or binary digits.

About this task

The HEX-OF intrinsic function can be used to convert data of any type to a human readable string of hexadecimal digits ("0" through "9", "A" through "F", and "a" through "f") that represent, in hexadecimal form, the underlying byte values of the data to be converted. The length of the output hex string in bytes is two times the length of the input argument string in bytes.

For example, FUNCTION HEX-OF('Hello, world!') returns 'C8859393966B40A6969993845A'.

Note: The first two hexadecimal digits 'C8' correspond to the EBCDIC encoding of the letter 'H'.

The argument to the HEX-OF intrinsic function can be a literal, a data item, or the result of an intrinsic function.

The BIT-OF intrinsic function can be used to convert data of any type to a human readable string of binary digits ("0" or "1") that represent, in bit string form, the underlying byte values of the data to be converted. The length of the output bit string in bytes is eight times the length of the input argument string in bytes.

For example, FUNCTION BIT-OF('Hello, world!') returns '11001000100001011001001110010011100101100110101101000000101001101001011010011001100100111000010001011010'.

Note: The first eight characters '11001000' of the output string correspond to the hexadecimal value x'C8', which matches the output of the HEX-OF intrinsic function shown above and corresponds to the EBCDIC encoding of the letter 'H'.

The argument to the BIT-OF intrinsic function can be a literal, a data item, or the result of an intrinsic function.

Related references  
BIT-OF (Enterprise COBOL for z/OS® Language Reference)
HEX-OF (Enterprise COBOL for z/OS Language Reference)