Bit Fields
- Bit Fields
- Bit fields are unsigned int members of structures that occupy a specified number of adjacent bits from one to sizeof(int). They may be used as an ordinary int variable in arithmetic and logical operations.
Bit fields are ordinary members of a structure and have a specific bit width. They are often used in conjunction with unions to provide bit access to a variable without masking operations.
Creating a Bit Field
Syntax
struct structName
{
unsigned int memberName1: bitWidth;
…
unsigned int memberNamen:bitWidth
}
Example
A bit field struct may be declared normally or as a typedef