Bit Manipulation with COBOL
SimoBITS - The COBOL Source Code
http://www.simotime.com
When technology complements business    Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.03.20 
  Introduction
 
  What It Does
  How to Use
  The COBOL Source Code
  The COBOL Copy File
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Glossary of Terms
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

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

SimoBITS, What It Does
(Next) (Previous) (Table-of-Contents)

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.

SimoBITS, How To Use
(Next) (Previous) (Table-of-Contents)

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.

The COBOL Source Code
(Next) (Previous) (Table-of-Contents)

The following is the COBOL Source Code.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    SIMOBITS.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2009 SimoTime Enterprises, LLC.            *
      *                                                               *
      * 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 Enterprises. 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           *
      * Enterprises.                                                  *
      *                                                               *
      * 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           *
      * Enterprises.                                                  *
      *                                                               *
      * SimoTime Enterprises makes no warranty or representations     *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any express or implied warranty,     *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Enterprises 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 Enterprises                                          *
      * 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 Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        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-2009 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           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 Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

The COBOL Copy File
(Next) (Previous) (Table-of-Contents)

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

      *****************************************************************
      *     Data Structure or Pass Area used for calling SIMOBITS.    *
      *****************************************************************
      *         Copyright (C) 1987-2006 SimoTime Enterprises          *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Enterprises                 *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      * When BTS-PASS-REQUEST is 'EXPAND  ' then
      *      BTS-PASS-BITS (a 1-btye field of 8-bits) is analyzed
      *      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' then
      *      BTS-PASS-BYTES (an 8-byte field of zeroes and ones) is
      *      analyzed 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...

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this document is to provide a COBOL Source member for viewing.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. 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 Enterprises.

Permission to use, copy, modify and distribute this software for a 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 Enterprises.

SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises 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.

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may view an example of a COBOL program that uses SimoBITS at http://www.simotime.com/cblbit01.htm.

You may view the complete list of SimoTime callable Modules or Driver Programs at http://www.simotime.com/simomods.htm.

The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.

This item will provide a link to  an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.

This document provides a quick summary of the  File Status Key  for VSAM data sets and QSAM files.

Check out  The SimoTime Library  for a wide range of topics for Programmers, Project Managers and Software Developers.

To review all the information available on this site start at  The SimoTime Home Page .

Glossary of Terms
(Next) (Previous) (Table-of-Contents)

Check out  The SimoTime Glossary  for a list of terms and definitions used in the documents provided by SimoTime.

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

We appreciate your comments and feedback.

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises 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. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. 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. 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
Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
When technology complements business
http://www.simotime.com