A set is stored as an array of bits, where each bit indicates if the element is in the set or excluded from the set. The maximum number of elements in a set is 256.
How many bytes the compiler uses to store a sets depends on the mode. For non-Delphi modes, the compiler stores small sets (less than 32 elements) in a Longint, if the set element type range allows it. This allows for faster processing and decreases program size. Otherwise, sets are stored in 32 bytes.
For Delphi mode, the compiler tries to store the set in the smallest number of bytes in which the set will fit.
The following program illustrates this:
When compiled in fpc mode, the program outputs the following:
In Delphi mode, the program will print:
Note that the set element size can be influenced with the {$PACKSET } directive, section 1.2.61, page 165.
The longword number of a specific element E is given by :
and the bit number within that 32-bit value is given by: