Bit Manipulation Using Structure

March 7, 2010 No Comments » Hits : 193






Bit Operations using Structure !!!

  1. To pack Several data objects in the single memory word , Bits are used .
  2. Flags can be In order to store the Boolean values ( T / F ).
  3. Eg. Gender of Person can be stored as [M/F] .
  4. By Setting the flag bit 1 we can set Gender as “Male” and “Female” by setting bit as 0
  5. A method to define a structure of packed information is known as bit fields.

Syntax :

struct databits{int b1 : 1;int b2 : 1;int b3 : 1;int b4 : 4;int b5 : 9;}data1;

How to access the Individual Bits ?

data1.b1data1.b2data1.b3data1.b4data1.b5

How to initialize Structure ?
struct databits{- - -- - -}data1 = { 1,1,0,10,234 };

Initialized Result -

data1.b1 = 1data1.b2 = 1data1.b3 = 0data1.b4 = 10data1.b5 = 234

Diagram :

Bookmark & Share

Incoming search terms: