The length of the bucket occupied by members in the struct (or shared body) is defined in units of bits.
The struct type containing bits is called the bits structure.
The bitwise structure is also a struct type, except that it contains a member of the integer type that defines the storage length in bits. The bit segment structure can save both storage space and facilitate operations.
The Definition Format of the median segment in the bit segment structure is as follows:
Unsigned <member name >:< binary digits>
For example:
Struct bytedata
{Unsigned A: 2;/* segment A, which occupies 2 places */
Unsigned: 6;/* unsigned segment, which occupies 6 digits, but cannot be accessed */
Unsigned: 0;/* the unsigned segment, which occupies 0. The next segment of the table starts from the bottom boundary */
Unsigned B: 10;/* segment B, which occupies 10 digits */
Int I;/* Member I, starting from the bottom boundary */
} Data;
Reference of bit segment data:
It is the same as the data reference in the structure member. However, you must note that the maximum value range of the bit segment should not be greater than the value range specified by the binary number. Otherwise, the excess part will be discarded.
For example, data. A = 2; but data. A = 10; is out of the range (A occupies 2 places, up to 3)
Pay attention to the following points for BIT data:
(1) A single segment must be stored in the same storage unit (Word) and cannot be stored across two units. If the unit space is not enough, the remaining space is not used. This segment is stored from the next unit.
(2) The next segment can start from the next storage unit by defining a bit segment with a length of 0.
(3) An anonymous segment can be defined.
(4) The length of the bit segment cannot exceed the length of the storage unit.
(5) The bitwise segment does not have an address, and the bitwise segment cannot be used for address fetch operations.
(6) Bit segments can be output in % d, % O, % x format.
(7) If the bits appear in the expression, the system automatically converts them to integers.