Bit-String Data

A bit-string is a sequence of binary digits (bits). The number of bits in the sequence is called the length of the value.

A bit-string of zero length is called a null string.

A bit-string variable or bit-string valued function is declared with the following attributes:

BIT(n)

or

BIT(n) ALIGNED | UNALIGNED

where n is an integer valued expression that specifies the maximum length of all string values that can be held by the variable or returned by the function.

If a value of less than n bits is assigned to a bit-string variable, the variable is extended on the right with zero bits to make it n bits long. If a value of more than n bits is assigned, only the leftmost n bits are stored, and the excess bits are truncated.

The ALIGNED attribute causes the associated bit-string variable to be aligned on the storage boundary (described in your Open PL/I User's Guide) so as to make it more efficiently accessed. This attribute may also cause the variable to occupy more than n bits, but it does not increase the size of values that can be stored in the variable.

The UNALIGNED attribute causes the associated bit-string variable to be aligned at the next available bit so as to reduce storage requirements. If neither ALIGNED nor UNALIGNED is specified, UNALIGNED is assumed by default.

In the following structure declaration,

DECLARE 1 S ALIGNED,
        2 A BIT(3),
        2 B BIT(7) UNALIGNED,
        2 C BIT(1) UNALIGNED;
        2 D BIT(5);

the bit strings are stored as follows:

Stored Bit Strings

In this example the A and D strings are aligned because they inherit the ALIGNED attribute from the structure declaration. A bit string occupies a full byte. If the structure S had been declared with the UNALIGNED attribute, the A and D strings would be unaligned.

Bit-string values are compared from left to right, a bit at a time until an inequality is found. The shorter operand is effectively extended by zero bits on the right to make it the length of the other operand for purposes of comparison.

A bit-string is not a word of storage in a computer and is not an arithmetic value. It is a sequence of bits that is always operated upon from left to right, just as a character string is operated upon from left to right.

A bit-string constant is written as a quoted string of zeros and ones followed by a B.

A bit string of length one is a boolean value with the possible values of '0'B and '1'B, which denote false and true, respectively.

Note: No assumptions should be made about the form in which a bit-string is stored.

Examples:

'1'B 
'10110'B
'O'B
''B

The last string in the previous set of examples is a null bit string.

Bit-string constants may also be written using a string of characters to represent the bit string:

'character string'Bn

where n is 1, 2, 3, or 4 and is the number of bits each character represents. The table below gives the set of permissible characters and shows the corresponding bit-string values. In this table, a '–' indicates 'invalid.'

Character    
B or B1     B2     B3     B4
0 0 00 000 0000
1 1 01 001 0001
2 10 010 0010
3 11 011 0011
4 100 0100
5 101 0101
6 110 0110
7 111 0111
8 1000
9 1001
A 1010
B 1011
C - - _ 1100
D 1101
E 1110
F 1111

For example:

Bit-String     Equivalent Value
'073'B3 '000111011'B
'A04'134 '101000000100'B