![](/images/backgrounds/286549/hp-sunsoft-pascal-4-0-users-manual-549395134x1.png)
6
In Pascal, a set type is implemented as a bit vector, which is similar to a C
In Pascal, bits are numbered within a byte from the most significant to least, as shown in Table
Table
Set | Bit Numbering |
|
|
set+3: | 31, 30, 29, 28, 27, 26, 25, 24 |
|
|
set+2: | 23, 22, 21, 20, 19, 18, 17, 16 |
|
|
set+1: | 15, 14, 13, 12, 11, 10, 9, 8 |
|
|
set+0: | 7, 6, 5, 4, 3, 2, 1, 0 |
|
|
In C, a set could be described as a
The nth element in a set [lower...upper] can be tested as follows:
#define LG2BITSLONG 5 /* log2( bits in long word) */ #define LG2BITSWORD 4 /* log2( bits in short word) */ #define MSKBITSLONG 0x1f
#define MSKBITSHORT 0x0
short *setptr; | /* | set as array of shorts */ | ||
int | upper; | /* | upper bound of the set */ | |
int | elem; | /* | ordinal value of set element */ | |
int | i; |
|
|
|
if | ( setptr[elem | >> LG2BITSWORD] | & | |
(1 << (elem & MSKBITSWORD)) | ) { | |||
| /* elem is in set */ |
| ||
} |
|
|
|
|
110 | Pascal 4.0 User’s Guide |