Structural bit structure name
{
Data type variable name: integer constant;
Data type variable name: integer constant;
} bit structure variable;
Among them, struct is the keyword, and the data type of bit structure must be integer int (unsigned or signed); The integer Changshu must be a non-negative integer of 0 ~ 15 to indicate how many bits there are, that is, binary digits. The variable name is optional and can be omitted. The definition of bit structure, examples are as follows.
Structure
{
Unsigned lbit: 8; //LBit occupies 8 bits of low byte 0 ~ 7 * * *.
Unsigned hbit 0: 4; //HBit0 occupies the high byte 0 ~ 3 * * * 4 bits.
Unsigned hbit1:3; //HBit 1 takes up 4 ~ 6 * * * 3 high bytes.
Unsigned hbit2:1; //HBit2 occupies the 7th bit of the high byte.
} bit;
Access to bit structure members is the same as access to structure members. For example, access to LBit members in a high-level structure can be written as follows.
A little. LBit
When using bit structure, pay attention to the following points.
Members in the 1.bit structure must be int, but they can be defined as unsigned or signed.
2. When the length of a bit structure member is 1, C5 1 language regards it as an unsigned type.
3. The total length (number of bits) of the bit structure is the sum of the number of bits defined by each bit member, which can exceed two bytes.
4. Members in a bit structure cannot use arrays and pointers, but bit structure variables can be arrays and pointers. If it is a pointer, its members are accessed in the same way as structural pointers.
5. Bit structures can be members of nested structures and used together with other structure members. Examples are as follows.
Structural students
{
char * name
int num
int age
char * sex
Floating score;
Unsigned reister:1;
Unsigned salary:1;
};