Microsoft KB Archive/59074

Using COBOL CALL X“F4” and X“F5” Functions to Manipulate Bits

PSS ID Number: Q59074 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: Microsoft COBOL Compiler Versions 3.0 and 3.0a have two extension routines that allow you to examine and alter the individual bits of a specific byte of data. These routines are CALL X“F4” (to change the individual bits in a byte) and CALL X“F5” (to examine the bits of a byte). Call X“F4” and CALL X“F5” are documented in the “Microsoft COBOL 3.0: Operating Guide” on Pages 8-25 through 8-27.

More Information: The following sample program demonstrates the use of the CALL X“F4” and CALL X“F5” Microsoft COBOL extension routines for bit manipulation. The data byte contains the value 170 decimal, which is 10101010 in binary representation. After the CALL X“F5” is executed, the data array contains the values 1,0,1,0,1,0,1,0; these values correspond to each bit of the data byte. CALL X“F4” is then invoked to return the changed bits (1,0,1,0,1,0,1,1) to the data byte. The final value of the data byte is then 171. $SET ANS85 OLDINDEX DATA DIVISION. WORKING-STORAGE SECTION. 01 THE-BYTE PIC 99 COMP-X. 01 THE-BYTE-ARRAY. 03 THE-BYTE-DATA PIC 99 COMP-X OCCURS 8 TIMES INDEXED BY COUNTER. PROCEDURE DIVISION. MOVE 1 TO COUNTER. * Place 10101010 (decimal 170) into THE-BYTE MOVE 170 TO THE-BYTE. CALL X“F5” USING THE-BYTE, THE-BYTE-ARRAY. DISPLAY “The byte array is:” PERFORM UNTIL COUNTER = 8 DISPLAY THE-BYTE-DATA(COUNTER) ADD 1 TO COUNTER END-PERFORM. * Change the last bit in the array to a 1. MOVE 1 TO THE-BYTE-DATA(8). CALL X“F4” USING THE-BYTE, THE-BYTE-ARRAY. * THE-BYTE now contains 10101011 (decimal 171). DISPLAY “The byte is:” THE-BYTE.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.