$X2C: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
m (misc cleanup)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<p>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. </p>
__NOTOC__
<p>The output is one half the length of the input. Each pair of hexadecimal characters in the output becomes an EBCDIC character. For example,  
<p>
C'01' = X'01' or E8C5E2 = 'YES.'</p>
The <var>$X2C</var> function changes a 2-byte character of input into 1-byte hexadecimal-equivalent EBCDIC characters. Called with a character string, <var>$X2C</var> returns a character string that is half as long. </p>
<b>Syntax</b>
<p>
<p>The format for the $X2C function is:</p>
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. </p>
<p class="code">$X2C(inputchar)   
<p>
There is no function to translate 2-byte hexadecimal characters to ASCII characters. </p>
<p>
The output is one half the length of the input. Each pair of hexadecimal characters in the output becomes an EBCDIC character. For example,  
<code>C'01' = X'01'</code>, and <code>E8C5E2 = 'YES'</code>.</p>
 
==Syntax==
<p>
The format for the <var>$X2C</var> function is:</p>
<p class="syntax">$X2C(<span class="term">inputchar</span>)   
</p>
</p>
<p>where inputchar is the input character string (either a %variable or a quoted literal) to be converted to one-byte hexadecimal-equivalent characters.</p>
<p>
<p>Input must be an even number of bytes (divisible by 2) and contain only combinations of the following characters:</p>
Where <var class="term">inputchar</var> is the input character string (either a %variable or a quoted literal) to be converted to one-byte hexadecimal-equivalent characters.</p>
<p>
Input must be an even number of bytes (divisible by 2) and contain only combinations of the following characters:</p>
<p class="code">0123456789ABCDEF
<p class="code">0123456789ABCDEF
</p>
</p>
<p>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.</p>
<p>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.</p>
<b>Example 1</b>
 
==Examples==
===Example 1===
<p class="code">BEGIN
<p class="code">BEGIN
   %INPUT_IN_HEX = '05'
   %INPUT_IN_HEX = '05'
Line 17: Line 30:
END
END
</p>
</p>
<b>Example 2</b>
 
===Example 2===
<p class="code">BEGIN
<p class="code">BEGIN
PRINT $X2C('C1C2C3')
PRINT $X2C('C1C2C3')
Line 24: Line 38:
(output is ABC)
(output is ABC)
</p>
</p>
<b>Example 3</b>
 
===Example 3===
<p class="code">BEGIN
<p class="code">BEGIN
PRINT $X2C('F1')
PRINT $X2C('F1')
Line 31: Line 46:
(output is 1)     
(output is 1)     
</p>
</p>
<b>Example 4</b>
 
<p>This example produces a hexadecimal to decimal conversion:</p>
===Example 4===
<p>
This example produces a hexadecimal-to-decimal conversion:</p>
<p class="code">PROCEDURE X2D
<p class="code">PROCEDURE X2D
B
B
Line 39: Line 56:
END PROCEDURE
END PROCEDURE
</p>
</p>
<p>resulting in this output:</p>
<p>
<p class="code">$$X2D ENTER HEX VALUE    <--- $READ prompt
This is the resulting output:</p>
FC35       <--- User enters some hexadecimal input
<p class="output">$$X2D enter hex value  <--- $READ prompt
64565       <--- Procedure prints output value in Decimal
FC35                   <--- User enters some hexadecimal input
64565                 <--- Procedure prints output value in Decimal
</p>
</p>
<p>&nbsp;</p>
 
[[Category:SOUL $functions]]
[[Category:SOUL $functions]]

Latest revision as of 20:54, 17 November 2015

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