Actions

EmSys

C - Bit-fields

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Bit-fields

  • A bit field, or field for short, is a set of adjacent bits within a single implementation defined storage unit, normally called as a ‘word’.
  • When storage is at premium or interfaces to hardware devices imposes data formats, it may be necessary to pack several variables into a large machine word, to be able to get at pieces of a word.
struct tagLSR {
    unsigned int DataReady	: 1;
    unsigned int OverrunErr	: 1;
    unsigned int ParityErr	: 1;
    unsigned int FrameErr	: 1;
    unsigned int Break	        : 1;
    unsigned int THEmpty	: 1;
    unsigned int TSEmpty	: 1;
    unsigned int Notused	: 1;
};
  • This declares a structure named tagLSR that contains eight 1-bit fields.
  • The number following the colon represents the field width in bits.