September 1998
Intermediate to advanced
848 pages
20h 13m
English
The second method of manipulating bits is to use a bit field, which is just a set of neighboring bits within an unsigned int. A bit field is set up with a structure declaration that labels each field and determines its width. For instance, the following declaration sets up four 1-bit fields:
struct {
unsigned int autfd : 1;
unsigned int bldfc : 1;
unsigned int undln : 1;
unsigned int itals : 1;
} prnt;
This definition causes prnt to contain four 1-bit fields. Now you can use the usual structure membership operator to assign values to individual fields:
prnt.itals = 0; prnt.undln = 1;
Because each of these particular fields is just 1 bit, 1 and 0 are the only values you can use for assignment. The variable prnt is stored in an ...
Read now
Unlock full access