$X2C

From m204wiki
Revision as of 20:54, 17 November 2015 by JAL (talk | contribs) (misc cleanup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The $X2C function changes a 2-byte character of input into 1-byte hexadecimal-equivalent EBCDIC characters. Called with a character string, $X2C returns a character string that is half as long.

The maximum input length is 255 bytes. If the input length is more than 255 bytes or if input contains invalid hexadecimal data, a null string is returned.

There is no function to translate 2-byte hexadecimal characters to ASCII characters.

The output is one half the length of the input. Each pair of hexadecimal characters in the output becomes an EBCDIC character. For example, C'01' = X'01', and E8C5E2 = 'YES'.

Syntax

The format for the $X2C function is:

$X2C(inputchar)

Where inputchar is the input character string (either a %variable or a quoted literal) to be converted to one-byte hexadecimal-equivalent characters.

Input must be an even number of bytes (divisible by 2) and contain only combinations of the following characters:

0123456789ABCDEF

If the input character string is invalid for any reason and cannot be converted, then the output string returned by the function is set to a null.

Examples

Example 1

BEGIN %INPUT_IN_HEX = '05' %PAD_CHAR = $X2C(%INPUT_IN_HEX) END

Example 2

BEGIN PRINT $X2C('C1C2C3') END (output is ABC)

Example 3

BEGIN PRINT $X2C('F1') END (output is 1)

Example 4

This example produces a hexadecimal-to-decimal conversion:

PROCEDURE X2D B PRINT $UNBIN($X2C($PAD($READ('X2D enter hex value'),'0',8))) END END PROCEDURE

This is the resulting output:

$$X2D enter hex value <--- $READ prompt FC35 <--- User enters some hexadecimal input 64565 <--- Procedure prints output value in Decimal