$X2C: Difference between revisions
m (Lower case text really prints lower case) |
m (misc cleanup) |
||
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' | 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> | ||
<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=" | <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> | <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> | ||
==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> | ||
===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> | ||
===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> | ||
<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 | <p> | ||
<p class=" | This is the resulting output:</p> | ||
<p class="output">$$X2D enter hex value <--- $READ prompt | |||
FC35 <--- User enters some hexadecimal input | FC35 <--- User enters some hexadecimal input | ||
64565 <--- Procedure prints output value in Decimal | 64565 <--- Procedure prints output value in Decimal | ||
</p> | </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