Logic Routines for Bit Manipulation

When you program in a COBOL environment, you deal with data that is composed of characters, fields, records, or files. However, there are occasions when you must deal with individual data bits. For example, bit manipulation is an important feature in applications that deal with:

There is a set of library routines for bit manipulation. These routines are:

CBL_NOT logical NOT
CBL_AND logical AND
CBL_OR logical OR
CBL_EQ logical EQuivalence
CBL_XOR logical eXclusive OR
CBL_IMP logical IMPlies

These logical operations give the results shown in the following truth table.

A

B

  0

0

0

1

1

0

1

1

CBL_NOT (not A) 1 1 0 0
CBL_AND (A AND B) 0 0 0 1
CBL_OR (A OR B) 0 1 1 1
CBL_EQ (A EQ B) 1 0 0 1
CBL_XOR (A XOR B) 0 1 1 0
CBL_IMO (A IMP B) 1 1 0 1

For example, when the CBL_EQ routine compares bits A and B, the resulting bit is set to 1 if both A and B are 0 or if both A and B are 1. Otherwise the resulting bit is set to 0.

Example of Bit Manipulation

Related Topics: