Bit Manipulation, COBOL
SimoBITS - The COBOL Source Code
  Table of Contents  v-19.00.00 - simobits.htm 
  Introduction
  SimoBITS, What It Does
  SimoBITS, How To Use
  The COBOL Source Code
  The COBOL Copy File
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Comments or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

This program provides the programmer with the ability to access the individual bits within a single byte. This is commonly referred to as the "COBOL BIT Manipulation" routine.

For an example of a program that calls this routine refer to the Current Server or Internet Access section of this document.

This document provides a listing of the COBOL source code for the callable routine SimoBITS. Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com


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-2024
SimoTime Technologies and Services
All Rights Reserved

Table of Contents Previous Section Next Section SimoBITS, What It Does

The SimoBITS routine (or callable program) will convert the bit information in a single byte to or from an eight-byte field of COBOL accessible zeroes and ones.

Table of Contents Previous Section Next Section SimoBITS, How To Use

The following will expand a single byte into eight bytes of 0's or 1's based on the bit settings within the one 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 field will be '01010101' upon return from the call to SIMOBITS.

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.

           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 field will be X'FF' or high-value upon return from the call to SIMOBITS.

A copy file is provided to define the pass area to be used when calling SimoBITS. The following statement is required in the WORKING STORAGE section of the calling program.

        COPY PASSBITS

Table of Contents Previous Section Next Section The COBOL Source Code

The following (SIMOBITS.cbl) is the COBOL Source Code.

       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 The COBOL Copy File

The following (PASSBITS.cpy) is the COBOL copy file that may be used when calling SimoBITS.

      *****************************************************************
      *                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 program provides the COBOL programmer with the ability to access the individual bits within a single byte. 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, Comment 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.

Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the Link to Internet icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the Link to Server icon.

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

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 an Extended List of Software Technologies that are available for review and evaluation. The software technologies (or Z-Packs) provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.

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 connect.

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 Comments 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
The COBOL Source Code for Bit Manipulation with COBOL
Copyright © 1987-2024
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com