Communicator 3000 MPE/iX Release 6.0 (Platform Software Release C.60.00) (30216-90269)

152 Chapter 10
Technical Articles
COBOL II/iX Enhancements
HP_BYTE_UNPACK
HP_BYTE_PACK
These procedures reside in the COBOL II run-time library in
XL.PUB.SYS, but may be called from any program running in Native
Mode.
The routines HP_BYTE_AND, HP_BYTE_OR, and HP_BYTE_XOR perform
bitwise AND, bitwise inclusive OR, and bitwise exclusive OR. The two
operands and the result may be any length, but must be the same
length, and must be an integral number of bytes. The three routines
have identical calling sequences. The first two parameters are the two
operands, passed by reference. The third parameter is the result, also
passed by reference. The final parameter is the length, in bytes, of the
operands, and is passed by value. The first three parameters may not
overlap, except in the case where two of them, or all three, are the same
data item.
Examples
CALL "HP_BYTE_AND" USING OPERAND-1, OPERAND-2, RESULT, \4\.
CALL "HP_BYTE_OR" USING DATA-ITEM, MY-BIT-MASK, RESULT, \2\.
CALL "HP_BYTE_XOR" USING INPUT-BUFFER (J:1), RUNNING-XOR,
RUNNING-XOR, \1\.
Note that in COBOL II/iX, backslashes ("\") are used to indicate that a
parameter is passed by value. If the parameter is a literal, the
backslashes are optional.
The routine HP_BYTE_NOT has the same calling sequence, except that
there is only one operand rather than two. The result is computed as
the bitwise complement of the operand. The operand and the result
must be the same length, and must be an integral number of bytes.
They may not overlap, except that the same data item may be used for
both.
Example
CALL "HP_BYTE_NOT" USING OPERAND, RESULT, \4\.
The routine HP_BYTE_UNPACK takes three parameters: an operand, a
result, and the length of the operand in bytes. The bits of the operand
are unpacked into the result, left to right. Each "zero" bit of the operand
becomes an ASCII "0" byte in the result; each "one" bit becomes an
ASCII "1" byte. The length specified is the byte length of the operand.
The byte length of the result must be 8 times the byte length of the
operand.
Example
01 FIELD-A PIC S9(4) COMP.
01 RESULT PIC X(16).
...
MOVE 5 TO FIELD-A.
CALL "HP_BYTE_UNPACK" USING FIELD-A, RESULT, \2\.
DISPLAY RESULT.
* Results in "0000000000000101".