COBOL Bit Processing
Bit Manipulation
  Table of Contents  v-24.01.01 - cblbit01.htm 
  Introduction
  EXPAND the bits of a one-byte field into bytes of an eight-byte field
  COMPRESS the bytes of an eight-byte field into bits of a one-byte field
  Call Interface
  Job Scripts
  The CMD Member
  The JCL Member
  The Bash Script
  COBOL Members
  Demonstration Program
  Bit Manipulation Routine
  Copy File for Linkage Areas
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Contact or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

This is an example of how COBOL can do bit-level manipulation. The three basic functions (or bit-level operations) provided are as follows.

1 Determine the setting of a bit (0 or 1).
2 Set a bit to 0.
3 Set a bit to 1.
  The Three Basic Functions provided by the Bit Manipulation Routine

This example uses an approach of converting the bit information in a single byte to or from an eight-byte field of COBOL accessible zeros and ones. This example contains one JCL member to execute the two COBOL programs. The main COBOL program (CBLBITC1.CBL) is used to demonstrate and test the bit manipulation functions. The bit manipulation functions are in a separate, callable COBOL program (SIMOBITS.CBL). Both COBOL programs were written and tested using the VS COBOL II dialect. Also, both COBOL programs will work with COBOL for MVS and COBOL/370.

A JCL member is provided to run the job as an MVS batch job on an IBM Mainframe System or as a project with Micro Focus Mainframe Express (MFE) running on a Windows System. A CMD member is provided to run the job with Micro Focus Net Express (MFE) running on a Windows System. A Bash Script File is provided to run the job on a Linux or UNIX System and GnuCOBOL (formerly known as Open COBOL) is used to compile the COBOL Programs.

In the world of programming there are many ways to solve a problem. This suite of programs is provided as a COBOL programming example of one of the possible solutions to the problem of determining and changing the bits within a byte. This example may serve as a tutorial for new programmers and as a reference for experienced programmers. Additional information (including the original Assembler routine that does bit manipulation) is provided in the Downloads and Links to Similar Pages section of this document.

This type of bit manipulation is quite often considered something that cannot be done using COBOL. Many years ago I was asked to provide a mainframe assembler routine to access the bits within a byte. I delivered the callable routine and was well paid for the task. However, something the client said bothered me, "I have been told this cannot be done in COBOL."

I have heard this statement many times over the years and in a number of instances it is simply not true. An assembler routine would probably be smaller and run faster. However, if the task could be accomplished in a reasonable manner using COBOL then the cost, effort, frustration and ongoing support of an assembler routine in a COBOL programming shop may not be worth these advantages. This is especially true if assembler expertise is not readily available.

Determining and changing the setting of a bit is possible using COBOL. An assembler routine or the use of a language extension is not required. The called COBOL routine (SIMOBITS) in this example provides two functions that are described in the following sections of this document.

Note: Refer to the Download and Links to Similar Pages section of this document for links to additional documents that discuss this topic.


We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.

Copyright © 1987-2025
SimoTime Technologies and Services
All Rights Reserved

Table of Contents Previous Section Next Section EXPAND the bits of a one-byte field into bytes of an eight-byte field

For each bit that is ON (1) in the BTS-PASS-BITS field the corresponding byte in the BTS-PASS-BYTES field is set to a value of one. For each bit that is OFF (0) in the BTS-PASS-BITS field the corresponding byte in the BTS-PASS-BYTES field is set to a value of zero.

 Input BTS-PASS-BITS, a one byte field (8-bits)
 Output BTS-PASS-BYTES, an eight byte field
 Example if BTS-PASS-BITS = x'55' then BTS-PASS-BYTES will be '01010101'
  Expand Function of the Bit manipulation Routine

Table of Contents Previous Section Next Section COMPRESS the bytes of an eight-byte field into bits of a one-byte field

For each byte that is a one in the BTS-PASS-BYTES field the corresponding bit in the BTS-PASS-BITS field is set to ON (1). For each byte that is zero in the BTS-PASS-BYTES field the corresponding bit in the BTS-PASS-BITS field is set to OFF (0).

 Input BTS-PASS-BYTES, an eight byte field
 Output BTS-PASS-BITS, a one byte field (8-bits)
 Example if BTS-PASS-BYTES = '01010101' then BTS-PASS-BITS will be set to x'55'
  Compress Function of the Bit manipulation Routine

Table of Contents Previous Section Next Section Call Interface

The callable interface requires a data structure to be defined. A copy file (PASSBITS.CPY) is provided with the following source code.

      *****************************************************************
      *                PASSBITS is a COBOL Copy File                  *
      *     Data Structure or Pass Area used for calling SIMOBITS.    *
      *         Copyright (C) 1987-2019 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      * When BTS-PASS-REQUEST is 'EXPAND  ' do analysis of
      *      BTS-PASS-BITS (a 1-btye field of 8-bits)
      *      and based on the bit settings a corresponding value of
      *      0 or 1 is set in the BTS-PASS-BYTES (an 8-byte field
      *      of zeroes and ones).
      *
      * When BTS-PASS-REQUEST is 'COMPRESS' do analysis of
      *      BTS-PASS-BYTES (an 8-byte field of zeroes and ones)
      *      and based on a value of 0 or 1 the corresponding
      *      bit in BTS-PASS-BITS (a 1-byte field of 8-bits) is
      *      switched ON or OFF.
      *
       01  BTS-PASS-AREA.
           05  BTS-PASS-REQUEST            PIC X(8).
           05  BTS-PASS-RESULT             PIC S9(9)   COMP.
           05  BTS-PASS-RECORD.
               10  BTS-PASS-BITS           PIC X.
               10  BTS-PASS-BYTES.
                   15  BTS-PASS-BYTE-01    PIC X.
                   15  BTS-PASS-BYTE-02    PIC X.
                   15  BTS-PASS-BYTE-03    PIC X.
                   15  BTS-PASS-BYTE-04    PIC X.
                   15  BTS-PASS-BYTE-05    PIC X.
                   15  BTS-PASS-BYTE-06    PIC X.
                   15  BTS-PASS-BYTE-07    PIC X.
                   15  BTS-PASS-BYTE-08    PIC X.
      *
      ***  PASSBITS - End-of-Copy File - - - - - - - - - - - PASSBITS *
      *****************************************************************
      *

The following will translate an eight character field of 0's and 1's to a one byte field with the bits set to match to 0's and 1's of the eight character field. Please note: the content of the BTS-PASS-REQUEST field must be upper case and contain 'COMPRESS'

      *****************************************************************
      * The coding required to do the call to the Byte-Bit Routine    *
      * (translate an 8-byte field to a 1-byte field).                *
      *****************************************************************
           MOVE '11111111'         to BTS-PASS-BYTES
           MOVE 'COMPRESS'         to BTS-PASS-REQUEST
           CALL 'SIMOBITS'      using BTS-PASS-AREA

In the preceding example the contents of BTS-PASS-BITS will be X'FF' or high-value upon return from the call to SIMOBITS.

The following will set the individual bytes of an eight character field to 0's or 1's based on the bit settings of a one byte field. Please note: the content of the BTS-PASS-REQUEST field must be upper case and contain 'EXPAND' followed by two spaces

      *****************************************************************
      * The coding required to do the call to the Byte-Bit Routine    *
      * (translate a 1-byte field to an 8-byte field).                *
      *****************************************************************
           MOVE X'55'              to BTS-PASS-BITS
           MOVE 'EXPAND  '         to BTS-PASS-REQUEST
           CALL 'SIMOBITS'      using BTS-PASS-AREA

In the preceding example the contents of BTS-PASS-BYTES will be '01010101' upon return from the call to SIMOBITS.

Table of Contents Previous Section Next Section Job Scripts

A job script may be defined as a text file containing job setup information followed by job steps that identify programs to be executed along with parameters unique to the job step. A job script may be created using a text editor. The naming of a job script is determined by the Operating System. A simple job script may contain a single job step that performs a single function. A typical job script will contain multiple job steps executed in a predefined sequence. The status of each job step may be tested at the end of each job step.

Table of Contents Previous Section Next Section The CMD Member

The following is the Windows Command file (CBLBITE1.cmd) that is required to run as a job on a Windows System using Micro Focus COBOL technology.

@echo OFF
     set CmdName=CBLBITE1
rem  * *******************************************************************
rem  *                Job Script - a Windows Command File                *
rem  *                 Provided by SimoTime Technologies                 *
rem  *            (C) Copyright 1987-2023 All Rights Reserved            *
rem  *              Web Site URL:   http://www.simotime.com              *
rem  *                    e-mail:   helpdesk@simotime.com                *
rem  * *******************************************************************
rem  *
rem  * Text    - COBOL and Bit Manipulation
rem  * Author  - SimoTime Technologies and Services
rem  * Date    - November 11, 2003
rem  * Version - 06.07.16
rem  *
rem  * This test case illustrates the use a COBOL program to do
rem  * bit manipulation. This suite of programs will convert between
rem  * a one-byte (eight-bits) field and an eight-byte field.
rem  *
rem  * When running with Micro Focus the IBMCOMP an NOTRUNC directives
rem  * will be required to maintain compatability with the mainframe
rem  * format and field sizes for binary fields.
rem  *
rem  * This technique provides for the use of a single COBOL source
rem  * program that may be compiled and executed on an IBM Mainframe
rem  * Linux, UNIX or Windows System.
rem  *
rem  * This Job Script will run on a Windows system with Micro
rem  * Focus COBOL.
rem  *
rem  *   ************
rem  *   * CBLBITE1 *
rem  *   ********cmd*
rem  *        *
rem  *   ************     ************
rem  *   *   call   ******* ENV1BASE *
rem  *   ************     ********cmd*
rem  *        *
rem  *        *
rem  *   ************     ************     ************
rem  *   *   run    ******* CBLBITC1 *******  SYSOUT  *
rem  *   ************     ********cbl*     *******lseq*
rem  *        *                *
rem  *        *                *
rem  *        *           ************
rem  *        *           * SIMOBITS *
rem  *        *           ********cbl*
rem  *   ************
rem  *   *   EOJ    *
rem  *   ************
rem  *
rem  * ********************************************************************
rem  *
     setlocal
     call ..\ENV1BASE %CmdName%
     set SYSOUT=%BASELIB1%\LOGS\SYSOUT_%CmdName%.txt
     if exist %SYSOUT% erase %SYSOUT%
rem  *
     call SIMONOTE "*******************************************************************************%CmdName% "
     call SimoNOTE "* Starting CmdName %CmdName%, V08.06.05, User is %USERNAME%"
     call SIMONOTE "* Job_Step 1 of 3, Preparing the System and Job Environment"
     set JobStatus=0
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem  *
     call SimoNOTE "* --------------------------------------------------------------------------- *"
     call SimoNOTE "* Job_Step 2 of 3, Execute the Bit Manipulation program"
     run CBLBITC1
     if not "%ERRORLEVEL%" == "0" set JobStatus=20
     if not "%JobStatus%" == "0" goto :EOJTAG
rem  *
:EOJTAG
     call SimoNOTE "* --------------------------------------------------------------------------- *"
     call SimoNOTE "* Job_Step 3 of 3, End of Job processing"
     if "%JobStatus%" == "0" goto :EOJAOK
:EOJNOK
     call SimoNOTE "* ABENDING CmdName %CmdName%, Job Status is %JobStatus% "
     goto :EOJEND
:EOJAOK
     call SimoNOTE "* Finished CmdName %CmdName%, Job Status is %JobStatus% "
     goto :EOJEND
:EOJEND
     call SimoNOTE "* Conclude SYSOUT is  %SYSOUT% "
     if not "SIMOGENS" == "BATCH" pause
     endlocal

Table of Contents Previous Section Next Section The JCL Member

The following is the mainframe JCL member (CBLBITJ1.jcl) that is required to run as a job on an IBM Mainframe System or as a Mainframe Express project on a Windows System.

//CBLBITJ1 JOB SIMOTIME,'CBL BIT MANIPULATE',CLASS=1,MSGCLASS=0,
//             NOTIFY=CSIP1
//* *******************************************************************
//*               Job Script - an MVS or ZOS JCL Member               *
//*        This Test Case is provided by SimoTime Technologies        *
//*            (C) Copyright 1987-2019 All Rights Reserved            *
//*              Web Site URL:   http://www.simotime.com              *
//*                    e-mail:   helpdesk@simotime.com                *
//* *******************************************************************
//*
//* Text   - COBOL calls COBOL for Bit and Byte manipulation
//* Author - SimoTime Technologies
//* Date   - January 01, 1989
//*
//* This set of programs illustrate the use a COBOL program to do
//* bit manipulation. This suite of programs will convert between
//* a one-byte (eight-bits) field and an eight-byte field.
//*
//* The DD statement for SYSOUT is required by this example. The
//* COBOL program may be compiled using the SYSOUT directive and
//* without the DD statement for SYSOUT an RTS173 or RTS227 may occur.
//*
//* This set of programs may be compiled and executed on a Mainframe
//* System with ZOS or a Linux, UNIX or Windows System with Micro Focus
//* Enterprise Server.
//*
//*   ************
//*   * CBLBITJ1 *
//*   ********jcl*
//*        *
//*        *
//*   ************     ************
//*   * CBLBITC1 *-----* DISPLAY  *
//*   ********cbl*     ************
//*        *   *
//*        *   *       ************
//*        *   *-CALL--* SIMOBITS *
//*        *           ********cbl*
//*        *
//*   ************
//*   *   EOJ    *
//*   ************
//*
//* *******************************************************************
//* Step 1 of 1, This is a single step job.
//*
//CBLBITS1 EXEC PGM=CBLBITC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

Table of Contents Previous Section Next Section The Bash Script

The following is the Bash Shell Script (cblbits1.sh) that is required to run as a job on a Linux or UNIX System. For this test case the COBOL programs were compiled and executed on a Linux (Ubuntu) System using GnuCOBOL.

#!/bin/bash
   JOBNAME=cblbits1
#  * *******************************************************************
#  *       Bash Script File - provided by SimoTime Technologies        *
#  *           (C) Copyright 1987-2018 All Rights Reserved             *
#  *             Web Site URL:   http://www.simotime.com               *
#  *                   e-mail:   helpdesk@simotime.com                 *
#  * *******************************************************************
#  *
#  * Text    - COBOL and Bit Manipulation
#  * Author  - SimoTime Technologies
#  * Date    - May 22, 2017
#  * Version - 06.07.16
#  *
#  * This set of programs will illustrate the use a primary COBOL
#  * program that makes a call to a secondary COBOL progam that does
#  * bit manipulation. This suite of programs will convert between a
#  * one-byte (eight-bits) field and an eight-byte field.
#  *
#  * The secondary COBOL program must be compiled using the IBMCOMP
#  * and NOTRUNC options in order to maintain compatability with the
#  * mainframe format and field sizes for binary fields.
#  *
#  * This technique provides a single set of source code that may be
#  * compiled and executed on an IBM Mainframe System, a Linux System
#  * or a UNIX System.
#  *
#  *   ************
#  *   * cblbits1 *
#  *   *********sh*
#  *        *
#  *        *
#  *   ************     ************     ************
#  *   * cobcrun  ******* CBLBITC1 *******  SYSOUT  *
#  *   ************     * --call-- *     ************
#  *        *           * SIMOBITS *
#  *        *           ********cbl*
#  *   ************
#  *   *   EOJ    *
#  *   ************
#  *
#  * ********************************************************************
#  * Step 1 of 2, Set the environment variables...
#  *
   JOBSTATUS=0
   export BASESYS1=/home/larry/SIMOSY76
   export COB_LIBS=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR
   export COB_LIBRARY_PATH=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR
   export SIMONOTE=$BASESYS1/LOGS/SYSOUT_BASHUSER_$JOBNAME.txt
   simonote.sh "Starting - Job Name is $JOBNAME"
#  *
#  * ********************************************************************
#  * Step 2 of 2, Run the programs, COBOL doing Bit Manipulation...
#  *
   cobcrun CBLBITC1
#  *
   simonote.sh "Finished - Job Name is $JOBNAME"


Table of Contents Previous Section Next Section COBOL Members

There are three (3) COBOL source members in this suite of programs, a mainline (or demonstration) program, a callable bit-manipulation routine and a copy file that defines the pass area.

Table of Contents Previous Section Next Section Demonstration Program

This program (CBLBITC1.cbl) was written to test the callable COBOL program (SIMOBITS.CBL) that does the conversion between a 1-byte field of 8-bits and a field of 8-bytes.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLBITC1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2019 SimoTime Technologies.                *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any non-commercial purpose and without fee is hereby      *
      * granted, provided the SimoTime copyright notice appear on all *
      * copies of the software. The SimoTime name or Logo may not be  *
      * used in any advertising or publicity pertaining to the use    *
      * of the software without the written permission of SimoTime    *
      * Technologies.                                                 *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Technologies. Once the fee is received by SimoTime   *
      * the latest version of the software will be delivered and a    *
      * license will be granted for use within an enterprise,         *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies makes no warranty or representations    *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any expressed or implied warranty,   *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Technologies shall not be liable for any direct, indirect,    *
      * special or consequential damages resulting from the loss of   *
      * use, data or projects, whether in an action of contract or    *
      * tort, arising out of or in connection with the use or         *
      * performance of this software                                  *
      *                                                               *
      * SimoTime Technologies                                         *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: CBLBITC1.CBL
      * Copy Files:    PASSBITS.CPY
      * Calls to:      SIMOBITS
      *****************************************************************
      *
      * CBLBITC1 - Call SIMOBITS to convert between bits and bytes.
      *
      * CALLING PROTOCOL
      * ----------------
      * Use standard procedure to RUN or ANIMATE.
      *
      * DESCRIPTION
      * -----------
      * This program will call a COBOL routine to access a
      * routine to convert between bits and bytes..
      *
      *          ************
      *          * CBLBITJ1 *
      *          ********jcl*
      *               *
      *               *
      *          ************     ************
      *          * CBLBITC1 *-----* CONSOLE  *
      *          ********cbl*     ******dsply*
      *               *
      *               *
      *          ************
      *          * SIMOBITS *
      *          ********cbl*
      *
      * This program calls SIMOBITS to perform two functions:
      *
      * EXPAND   - translate the bits of a one-byte field to bytes
      *            in an eight-byte field.
      * COMPRESS - translate the bytes of an eight-byte field into
      *            bits in a one-byte field.
      *
      *****************************************************************
      * The EXPAND function will do the following:
      *
      * Input:  BTS-PASS-BITS, a one byte field (8-bits)
      * OUTPUT: BTS-PASS-BYTES, an eight byte field
      *
      * For each bit that is on in the BTS-PASS-BITS field set the
      * corresponding byte in the BTS-PASS-BYTES field to a value
      * of one.
      *
      * For each bit that is off in the BTS-PASS-BITS field set the
      * corresponding byte in the BTS-PASS-
      * BYTES field to a value of zero.
      *
      * Example: if   BTS-PASS-BITS = x'55'
      *          then BTS-PASS-BYTES will be '01010101'
      *
      *****************************************************************
      * The COMPRESS function will do the following:
      *
      * Input:  BTS-PASS-BYTES, an eight byte field
      * Output: BTS-PASS-BITS, a one byte field (8-bits)
      *
      * For each byte that is a one in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to ON (1)
      *
      * For each byte that is zero in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to OFF (0).
      *
      * Example: if   BTS-PASS-BYTES = '01010101'
      *          then BTS-PASS-BITS set to x'55'
      *
      *****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1989/02/27 Simmons, Created program.
      * 1997/03/17 Simmons, Updated for call to SIMOBITS.
      *
      *****************************************************************
      *
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLBITC1 '.
           05  T2 pic X(34) value 'Convert between Bits and Bytes    '.
           05  T3 pic X(10) value ' v08.06.05'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLBITC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2019 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLBITC1 '.
           05  C2 pic X(32) value 'Thank you for using this program'.
           05  C3 pic X(32) value ' provided from SimoTime Technolo'.
           05  C4 pic X(04) value 'gies'.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLBITC1 '.
           05  C2 pic X(32) value 'Please send all inquires or sugg'.
           05  C3 pic X(32) value 'estions to the helpdesk@simotime'.
           05  C4 pic X(04) value '.com'.

       COPY PASSBITS.

      *****************************************************************
      *    BTS-PASS-REQUEST values when calling SIMOBITS.
      *    ------------------------------------------------------------
       01  REQUEST-4-EXPAND        pic X(8)    value 'EXPAND  '.
       01  REQUEST-4-COMPRESS      pic X(8)    value 'COMPRESS'.

      *****************************************************************
      *    Buffer used for posting messages to the console.
      *    ------------------------------------------------------------
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLBITC1 '.
           05  MESSAGE-TEXT        pic X(68).

      *****************************************************************
      *    Work fields used for testing call to SIMOBITS.
      *    ------------------------------------------------------------
       01  HEX-00                  pic X.
       01  HEX-55                  pic X.
       01  HEX-AA                  pic X.
       01  HEX-FF                  pic X.

       01  BYTES-00                pic X(8).
       01  BYTES-55                pic X(8).
       01  BYTES-AA                pic X(8).
       01  BYTES-FF                pic X(8).

       01  ZERO-VALUE              pic 9       value 0.
       01  MINUS-ONE               pic S9      value -1.
       01  MINUS-ONE-X             redefines   MINUS-ONE
                                   pic X.
       01  POSITIVE-BIT-VALUE      pic X(8)    value '00000000'.
       01  NEGATIVE-BIT-VALUE      pic X(8)    value '00000000'.

       01  THREE-BYTES.
           05  PACK-03             pic S9(5)   comp-3  value 0.
       01  TWO-BYTES               pic X(2)    value '00'.
       01  EIGHT-BYTES             pic X(8)    value LOW-VALUES.

       01  THE-EASY-WAY.
           05  FILLER              pic X(9)    value 'Efficient'.
           05  FILLER              pic X(10)   value ', PACK-03 '.
           05  PACK-03-E1L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E1R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-E2L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E2R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-E3L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E3R         pic X(4)    value SPACES.
           05  FILLER              pic X(13)   value ', UNPACKED-5='.
           05  UNPACKED-5          pic 9(5)    value 0.

       01  THE-HARD-WAY.
           05  FILLER              pic X(9)    value 'Difficult'.
           05  FILLER              pic X(10)   value ', PACK-03 '.
           05  PACK-03-H1L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H1R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-H2L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H2R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-H3L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H3R         pic X(4)    value SPACES.
           05  FILLER              pic X(13)   value ', FIVE-BYTES='.
           05  FIVE-BYTES          pic X(5)    value '00000'.

       01  ALPHABET-UPPER pic X(26) value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

       01  IX-1           pic 9(3) value 0.
       01  IX-2           pic 9(3) value 0.
       01  IX-3           pic 9(3) value 0.

      *****************************************************************
       PROCEDURE DIVISION.

           perform Z-POST-COPYRIGHT

           perform BYTES-TO-BITS-COMPRESS.

           perform BITS-TO-BYTES-EXPAND.

           perform ALPHABET-DUMP.

           perform COBOL-UNPACK.

           perform Z-THANK-YOU.

           move ZERO to RETURN-CODE

           GOBACK.

      *****************************************************************
       ALPHABET-DUMP.
           move 'Starting ALPHABET-DUMP Routine...' to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           add 1 to ZERO giving IX-1
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           perform 26 times
               move ALPHABET-UPPER(IX-1:1) to BTS-PASS-BITS
               call 'SIMOBITS' using BTS-PASS-AREA
               move 'Position nnn is x, the binary value is xxxx-xxxx'
                 to MESSAGE-TEXT
               move IX-1                to MESSAGE-TEXT(10:03)
               move BTS-PASS-BITS       to MESSAGE-TEXT(17:1)
               move BTS-PASS-BYTES(1:4) to MESSAGE-TEXT(40:4)
               move BTS-PASS-BYTES(5:4) to MESSAGE-TEXT(45:4)
               perform Z-POST-MESSAGE
               add 1 to IX-1
           end-perform
           exit.

      *****************************************************************
       BITS-TO-BYTES-EXPAND.
           move 'Starting BITS-TO-BYTES-EXPAND Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           move HEX-00 to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-00
           perform DISPLAY-BYTES

           move HEX-FF to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-FF
           perform DISPLAY-BYTES

           move HEX-55 to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-55
           perform DISPLAY-BYTES

           move HEX-AA to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-AA
           perform DISPLAY-BYTES

           exit.

      *****************************************************************
       BYTES-TO-BITS-COMPRESS.
           move 'Starting BYTES-TO-BITS-COMPRESS Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           move '00000000' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'SIMOBITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-00
           perform DISPLAY-BYTES

           move '11111111' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'SIMOBITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-FF
           perform DISPLAY-BYTES

           move '01010101' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'SIMOBITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-55
           perform DISPLAY-BYTES

           move '10101010' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'SIMOBITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-AA
           perform DISPLAY-BYTES

           exit.

      *****************************************************************
      * If you thought the UnPack was reserved for the mainframe      *
      * assembler programmers then take a look at the following       *
      * routine. The is a bit of an esoteric use of bit mainipulation *
      * but it does unpack a data string into a new data string.      *
      *                                                               *
      * A quicker and better way to unpack a field is as follows:     *
      *    ADD PACKED-FIELD TO ZERO GIVING UNPACKED-FIELD.            *
      *****************************************************************
       COBOL-UNPACK.
           move 'Starting the COBOL-UNPACK Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           add 615 to ZERO giving PACK-03

      *    Do the UNPACK the easy way...
           add PACK-03 to ZERO giving UNPACKED-5

      *    First, determine the bit configuration for zero to be
      *    used to set the left-nibble of the unpacked bytes.
      *    Then determine the negative sign bit configuration.
      *    This section of code is used so the program will run
      *    properly in both an EBCDIC and ASCII environment.
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           move ZERO-VALUE       to BTS-PASS-BITS
           call 'SIMOBITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES   to POSITIVE-BIT-VALUE

           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           move MINUS-ONE-X      to BTS-PASS-BITS
           call 'SIMOBITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES   to NEGATIVE-BIT-VALUE
           move '0000'           to NEGATIVE-BIT-VALUE(5:4)
      *    Do the UNPACK the esoteric way...
           move all '0' to FIVE-BYTES
           add 1 to ZERO giving IX-1
           add 1 to ZERO giving IX-2
           add 3 to ZERO giving IX-3
           perform until IX-3 = 1
               move REQUEST-4-EXPAND    to BTS-PASS-REQUEST
               move THREE-BYTES(IX-1:1) to BTS-PASS-BITS
               call 'SIMOBITS'       using BTS-PASS-AREA
               move BTS-PASS-BYTES      to EIGHT-BYTES

               move REQUEST-4-COMPRESS  to BTS-PASS-REQUEST
               move POSITIVE-BIT-VALUE      to BTS-PASS-BYTES

               move EIGHT-BYTES(1:4)    to BTS-PASS-BYTES(5:4)
               call 'SIMOBITS'       using BTS-PASS-AREA
               move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
               add 1 to IX-2
               move EIGHT-BYTES(5:4)    to BTS-PASS-BYTES(5:4)
               call 'SIMOBITS'       using BTS-PASS-AREA
               move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
               subtract 1 from IX-3
               add 1 to IX-2
               add 1 to IX-1
           end-perform
           perform COBOL-UNPACK-UNITS.

      *    Display the results...
           perform COBOL-UNPACK-POST-EFFICIENT
           perform COBOL-UNPACK-POST-DIFFICULT

           move 'Finished the COBOL-UNPACK Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           exit.
      *---------------------------------------------------------------*
       COBOL-UNPACK-POST-DIFFICULT.
           move THREE-BYTES(1:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H1L
           move BTS-PASS-BYTES(5:4) to PACK-03-H1R

           move THREE-BYTES(2:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H2L
           move BTS-PASS-BYTES(5:4) to PACK-03-H2R

           move THREE-BYTES(3:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H3L
           move BTS-PASS-BYTES(5:4) to PACK-03-H3R

           move THE-HARD-WAY to MESSAGE-TEXT
           perform Z-POST-MESSAGE
           exit.

      *---------------------------------------------------------------*
       COBOL-UNPACK-POST-EFFICIENT.
           move THREE-BYTES(1:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E1L
           move BTS-PASS-BYTES(5:4) to PACK-03-E1R

           move THREE-BYTES(2:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E2L
           move BTS-PASS-BYTES(5:4) to PACK-03-E2R

           move THREE-BYTES(3:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'SIMOBITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E3L
           move BTS-PASS-BYTES(5:4) to PACK-03-E3R

           move THE-EASY-WAY to MESSAGE-TEXT
           perform Z-POST-MESSAGE
           exit.

      *---------------------------------------------------------------*
       COBOL-UNPACK-UNITS.
           move REQUEST-4-EXPAND    to BTS-PASS-REQUEST
           move THREE-BYTES(IX-1:1) to BTS-PASS-BITS
           call 'SIMOBITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES      to EIGHT-BYTES

           move REQUEST-4-COMPRESS  to BTS-PASS-REQUEST
           if  PACK-03 < 0
               move NEGATIVE-BIT-VALUE      to BTS-PASS-BYTES
           else
               move POSITIVE-BIT-VALUE      to BTS-PASS-BYTES
           end-if
           move EIGHT-BYTES(1:4)    to BTS-PASS-BYTES(5:4)
      *    move EIGHT-BYTES(5:4)    to BTS-PASS-BYTES(1:4)
           call 'SIMOBITS'       using BTS-PASS-AREA
           move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
           exit.

      *****************************************************************
       DISPLAY-BYTES.
           move 'Binary value is '     to MESSAGE-TEXT(1:16)
           move BTS-PASS-BYTES(1:4)    to MESSAGE-TEXT(17:4)
           move '-'                    to MESSAGE-TEXT(21:1)
           move BTS-PASS-BYTES(5:4)    to MESSAGE-TEXT(22:4)
           perform Z-POST-MESSAGE
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE
           display SIM-COPYRIGHT
           exit.

      *****************************************************************
       Z-POST-MESSAGE.
           display MESSAGE-BUFFER
           move SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01
           display SIM-THANKS-02
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section Bit Manipulation Routine

This program (SIMOBITS.cbl) was originally written to be used as a teaching and learning aid. It was first used in a production environment to replace a callable 370 assembler routine. Today, this program is used in a number of mainframe shops and it is the program of choice used by SimoTime. Also, the program has been tested and deployed on the PC with Mainframe Express or Net Express from Micro Focus.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    SIMOBITS.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2019 SimoTime Technologies.                *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Technologies. Once the fee is received by SimoTime   *
      * the latest version of the software will be delivered and a    *
      * license will be granted for use within an enterprise,         *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Technologies.                                                 *
      *                                                               *
      * Permission to use, copy and modify this software for any      *
      * non-commercial purpose and without fee is hereby granted,     *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies makes no warranty or representations    *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any expressed or implied warranty,   *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Technologies shall not be liable for any direct, indirect,    *
      * special or consequential damages resulting from the loss of   *
      * use, data or projects, whether in an action of contract or    *
      * tort, arising out of or in connection with the use or         *
      * performance of this software                                  *
      *                                                               *
      * SimoTime Technologies                                         *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: SIMOBITS.CBL
      * Copy Files:    PASSBITS.CPY
      *****************************************************************
      *
      * SIMOBITS - A called routine for bit and byte conversions.
      *
      * CALLING PROTOCOL
      * ----------------
      * Use standard COBOL calling procedures.
      *
      * DESCRIPTION
      * -----------
      * This program will do Bit and Byte conversions.
      *
      ****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1989/02/27 Simmons, Created program.
      * 1989/02/27 Simmons, no changes to date
      *
      *****************************************************************
      *
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* SIMOBITS '.
           05  T2 pic X(34) value 'Convert between Bits and Bytes    '.
           05  T3 pic X(10) value ' v06.11.14'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* SIMOBITS '.
           05  C2 pic X(20) value 'Copyright 1987-2019 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  FIRST-TIME              pic X       value 'Y'.

       01  A-COMPILE-TIME          pic X       value 'A'.
       01  A-EBC                   pic X       value x'C1'.
       01  A-ASC                   pic X       value x'41'.

       01  COMPRESS                pic X(8)  value 'COMPRESS'.
       01  EXPAND                  pic X(8)  value 'EXPAND  '.
       01  BIT-ON                  pic 9     value 1.
       01  BIT-OFF                 pic 9     value 0.

       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* SIMOBITS '.
           05  MESSAGE-TEXT        pic X(68).

       01  TWO-BYTES.
           05  TWO-BYTES-01        pic X.
           05  TWO-BYTES-02        pic X.
       01  TWO-BYTES-BINARY        redefines   TWO-BYTES
                                   pic S9(4)   binary.

       01  IX-1                    pic 99      value 0.
       01  REGISTER-1              pic S9(5)   value 0.
      *****************************************************************
       LINKAGE SECTION.
       COPY PASSBITS.

      *****************************************************************
       PROCEDURE DIVISION using BTS-PASS-AREA.

       MAIN-ROUTINE.
           move ZERO to BTS-PASS-RESULT

           if  FIRST-TIME not = 'N'
               perform Z-POST-COPYRIGHT
               move 'N' to FIRST-TIME
           end-if

           evaluate BTS-PASS-REQUEST
               when COMPRESS perform COMPRESS-BYTES
               when EXPAND   perform EXPAND-BITS
               when OTHER    perform INVALID-REQUEST
           end-evaluate

           add BTS-PASS-RESULT to ZERO giving RETURN-CODE

           GOBACK.

      *****************************************************************
       INVALID-REQUEST.
           display '* SIMOBITS, INVALID REQUEST, ' BTS-PASS-REQUEST
           add 16 to ZERO giving BTS-PASS-RESULT
           exit.

      *****************************************************************
      * Input:  BTS-PASS-BYTES, an eight byte field
      * Output: BTS-PASS-BITS, a one byte field (8-bits)
      *
      * For each byte that is a one in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to ON (1)
      *
      * For each byte that is zero in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to OFF (0).
      *
      * Example:
      * BTS-PASS-BYTES = '01010101' then BTS-PASS-BITS set to x'55'
      *****************************************************************
       COMPRESS-BYTES.
           subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
           add 1   to ZERO giving IX-1
           add 128 to ZERO giving REGISTER-1
           perform until IX-1 GREATER THAN 8
               if  BTS-PASS-BYTES(IX-1:1) = BIT-ON
                   add REGISTER-1 to TWO-BYTES-BINARY
               else
                   if  BTS-PASS-BYTES(IX-1:1) not = BIT-OFF
                       move '8-Byte string must be zeroes or ones...'
                         to MESSAGE-TEXT
                       perform Z-POST-MESSAGE
                       add 8 to IX-1
                       add 8 to ZERO giving BTS-PASS-RESULT
                   end-if
               end-if
               divide 2 INTO REGISTER-1
               add 1 to IX-1
           end-perform
           move TWO-BYTES-02 to BTS-PASS-BITS
           exit.

      *****************************************************************
      * Input:  BTS-PASS-BITS, a one byte field (8-bits)
      * OUTPUT: BTS-PASS-BYTES, an eight byte field
      *
      * For each bit that is on in BTS-PASS-BITS set the
      * corresponding byte in BTS-PASS-BYTES to a value of one.
      *
      * For each bit that is off in BTS-PASS-BITS set the
      * corresponding byte in BTS-PASS-BYTES to a value of zero.
      *
      * Example:
      * BTS-PASS-BITS = x'55' then BTS-PASS-BYTES will be '01010101'
      *****************************************************************
       EXPAND-BITS.
           subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
           add 1   to ZERO giving IX-1
           add 128 to ZERO giving REGISTER-1
           move BTS-PASS-BITS to TWO-BYTES-02
           perform 8 times
               if  TWO-BYTES-BINARY = REGISTER-1
               or  TWO-BYTES-BINARY > REGISTER-1
                   move BIT-ON to BTS-PASS-BYTES(IX-1:1)
                   subtract REGISTER-1 from TWO-BYTES-BINARY
               else
                   move BIT-OFF to BTS-PASS-BYTES(IX-1:1)
               end-if
               divide 2 INTO REGISTER-1
               add 1 to IX-1
           end-perform
           exit.

      *****************************************************************
      *    Display the Copyright data-structure...
      *    ------------------------------------------------------------
       Z-POST-COPYRIGHT.
           display SIM-TITLE      upon console
           display SIM-COPYRIGHT  upon console
           exit.
       Z-POST-MESSAGE.
           display MESSAGE-BUFFER upon console
           move SPACES to MESSAGE-TEXT
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section Copy File for Linkage Areas

This copy file (PASSBITS.cpy) provides a convenient method for defining the data areas (or fields) that are used to pass information between the demo program and the bit and byte conversion routine.

      *****************************************************************
      *                PASSBITS is a COBOL Copy File                  *
      *     Data Structure or Pass Area used for calling SIMOBITS.    *
      *         Copyright (C) 1987-2019 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      * When BTS-PASS-REQUEST is 'EXPAND  ' do analysis of
      *      BTS-PASS-BITS (a 1-btye field of 8-bits)
      *      and based on the bit settings a corresponding value of
      *      0 or 1 is set in the BTS-PASS-BYTES (an 8-byte field
      *      of zeroes and ones).
      *
      * When BTS-PASS-REQUEST is 'COMPRESS' do analysis of
      *      BTS-PASS-BYTES (an 8-byte field of zeroes and ones)
      *      and based on a value of 0 or 1 the corresponding
      *      bit in BTS-PASS-BITS (a 1-byte field of 8-bits) is
      *      switched ON or OFF.
      *
       01  BTS-PASS-AREA.
           05  BTS-PASS-REQUEST            PIC X(8).
           05  BTS-PASS-RESULT             PIC S9(9)   COMP.
           05  BTS-PASS-RECORD.
               10  BTS-PASS-BITS           PIC X.
               10  BTS-PASS-BYTES.
                   15  BTS-PASS-BYTE-01    PIC X.
                   15  BTS-PASS-BYTE-02    PIC X.
                   15  BTS-PASS-BYTE-03    PIC X.
                   15  BTS-PASS-BYTE-04    PIC X.
                   15  BTS-PASS-BYTE-05    PIC X.
                   15  BTS-PASS-BYTE-06    PIC X.
                   15  BTS-PASS-BYTE-07    PIC X.
                   15  BTS-PASS-BYTE-08    PIC X.
      *
      ***  PASSBITS - End-of-Copy File - - - - - - - - - - - PASSBITS *
      *****************************************************************
      *

Table of Contents Previous Section Next Section Summary

This suite of programs is provided as a COBOL programming example of one of the possible solutions to the problem of determining and changing the bits within a byte. This example uses an approach of converting the bit information in a single byte to or from an eight-byte field of COBOL accessible zeros and ones. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.

In the world of programming there are many ways to solve a problem. This documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.

SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please contact us using the information in the  Contact or Feedback  section of this document.

Table of Contents Previous Section Next Section Software Agreement and Disclaimer

Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Technologies.

SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.

Table of Contents Previous Section Next Section Downloads and Links

This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an Internet connection.

Note: A SimoTime License is required for the items to be made available on a local system or server.

Table of Contents Previous Section Next Section Current Server or Internet Access

The following links may be to the current server or to the Internet.

Link to Internet   Link to Server   Explore Bit Manipulation using a COBOL program calling Assembler to do the accessing of individuals bits within a byte.

Link to Internet   Link to Server   Explore How to do a logical AND Function using a COBOL program that calls a COBOL routine to do the actual logical AND of two data strings.

Link to Internet   Link to Server   Explore How to do a logical OR Function using a COBOL program that calls a COBOL routine to do the actual logical OR of two data strings.

Link to Internet   Link to Server   Explore How to do an Exclusive OR (XOR) using a COBOL program that calls a COBOL routine to do the actual XOR of two data strings.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to Server   Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.

Link to Internet   Link to Server   Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

The following links will require an Internet connection.

This suite of programs and documentation is available for download. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.

A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection

Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection.

Explore the GnuCOBOL Technologies available from SourceForge. SourceForge is an Open Source community resource dedicated to helping open source projects be as successful as possible. GnuCOBOL (formerly OpenCOBOL) is a COBOL compiler with run time support. The compiler (cobc) translates COBOL source to executable using intermediate C, designated C compiler and linker. This link will require an Internet Connection.

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Contact or Feedback

This document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.

1. Send an e-mail to our helpdesk.
1.1. helpdesk@simotime.com.
2. Our telephone numbers are as follows.
2.1. 1 415 763-9430 office-helpdesk
2.2. 1 415 827-7045 mobile

 

We appreciate hearing from you.

Table of Contents Previous Section Next Section Company Overview

SimoTime Technologies was founded in 1987 and is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems.

Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms.

Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SimoTime has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment.

Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com


Return-to-Top
COBOL Bit Processing, Bit Manipulation
Copyright © 1987-2025
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com