* :--------------------------------------- * ------------------------: BITES TO BYTES OR BYTES TO BITS * :--------------------------------------- * : This copybook is used for the * : FUNC-BITS-TO-BYTES and * : FUNC-BYTES-TO-BITS function calls. * : * : * : There are occasions where you need to * : encode data into the bits of a single * : byte, or extract a specific bit from * : a byte. These functions exist in some * : compilers and not others. We provide * : these functions for simplicity. * : * : FUNC-BITS-TO-BYTES * : This function takes an array of 1 byte * : fields and treats each as if it * : were a "bit", and packs each group of * : 8 such "bits" into a single byte. * : * : * : FUNC-BYTES-TO-BITS * : This function takes one or more Bytes * : and extracts each bit thereof into a * : seperate 1 byte field called a "bit. * : * : * : In either Function, you must specify * : the NUMBER OF BITS. This will be the * : number of input bits for Bits-to-bytes * : and the number of output bits for * : bytes-to-bits * : * : Failure to specify bits correctly may * : cause these functions to overlay * : adjacent working storage areas. * : * : Calling with bit-count = zero is a * : fatal error. * : * : The Bit fields contain low-values * : when they are "off" (or zero), and * : any other value when they are "on" * : (or one). Bits extracted will contain * : a character "X" for the on state and * : low-value for the off state. * : * : * : The source field will not be changed * : * : * : * : Example: Assume you have 10 bit flags * : that you want to back into bytes. * : This will require 1 full byte and two * : bits of a second byte. * : * : Position: 1234567890 * : Content: 1tA 4 !$ * : (blanks represent low values here) * : * : Since ANY non-low value "bit" is * : treated as if it were a "1" bit (on) * : you can think of this as 10 binary * : digits: * : Position: 1234567890 * : Digits: 1110010011 * : * : Calling Bits-To-Bytes yields a 2 byte * : field (PIC XX) with bits 1-8 packed * : into byte 1 and bits 9 and 10 packed * : into byte 2. * : Byte one would contain hexidecimal * : E4, 228 decimal, a Sum Sign. * : Byte two would contain hexidecimal * : C0, 192 decimal, a left bottom corner * : * : Note that unused positions in the out- * : put BYTES are set to Off or Zero. * : * : Similarly, calling Bytes-To-Bits with * : with a Bit-count of 8 and a single * : input character of "A" will yield 8 * : one character "bit" fields containing * : "X X" (blanks shown here = Lows) * : * : * To use: * * COPY WIN32API. * COPY BITOPS. * * --- --- Typical call --- BITS-TO-BYTES --- --- * * : Set how many bits we want to pack * MOVE 24 TO BITOPS-BIT-COUNT * : Move in our bit switches * MOVE some-bit-switches TO BITOPS-UNPACKED-DATA * : Set the function * SET FUNC-BITS-TO-BYTES TO TRUE * CALL 'GSWINAPI' USING WIN32API-PARMS * BITOPS-BIT-COUNT * BITOPS-UNPACKED-DATA * BITOPS-PACKED-DATA * WIN32API-D * WIN32API-E * WIN32API-F * * --- --- Typical call --- BYTES-TO-BITS --- --- * * : Set how many bits we want to Unpack * MOVE 16 TO BITOPS-BIT-COUNT * : Move in our BYTES to be unpacked * MOVE some-packed-data TO BITOPS-PACKED-DATA * : Set the function * SET FUNC-BYTES-TO-BITS TO TRUE * CALL 'GSWINAPI' USING WIN32API-PARMS * BITOPS-BIT-COUNT * BITOPS-UNPACKED-DATA * BITOPS-PACKED-DATA * WIN32API-D * WIN32API-E * WIN32API-F * * ---------------------------------------------------------------- 01 BITOPS-BIT-COUNT PIC 9(4) COMP-5. * : These next two serve as examples only, * : feel free to stubstitue your own data * : areas of any size up to 32k. 01 BITOPS-UNPACKED-DATA. 05 BITOPS-BIT OCCURS 40 PIC X. 01 BITOPS-PACKED-DATA PIC X(5).