TYPE and UNION structures may contain bit variables, which are named BIT (unsigned values) or SBIT (signed values). Each bit variable may occupy from 1 to 31 bits. When used in a TYPE, bit variables are packed one after another up to a total of 32 bits per bit field. When used in a UNION, all bit variables overlay each other, starting at the first bit position.
Bit variables may only be used as TYPE or UNION members, not as scalar, array, or pointer variables. The size of a bit variable is defined as:
var AS BIT * nlit [IN BYTE|WORD|DWORD]
where the term "* nlit" defines the number of bits (1 to 31), and the optional term "IN BYTE|WORD|DWORD", if present, defines the start of a new bit field of 1, 2, or 4 bytes.
valu AS BIT * 31 IN DWORD
sign AS SBIT * 1
nybl2 AS BIT * 4 IN BYTE
nybl1 AS BIT * 4
The example type above is 5 bytes in size, containing a 4-byte bit field and a 1-byte bit field. In this case, each contain 2 bit variables of varying size. The range of values which may be stored depends upon the number of bits available. For example, "BIT * 4" has a range of 0 to 15, "SBIT * 1" has a range of -1 to 0, and "SBIT * 5" has a range of -16 to +15. BIT and SBIT variables may not be used with SHIFT or ROTATE statements.
Part1 AS BIT * 8 IN DWORD
Part2 AS BIT * 16
The example union above is 2 bytes in size, containing an 8-bit field and an overlapping 16-bit field.
TYPE/END TYPE block
UNION/END UNION statements