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.b1
data1.b2
data1.b3
data1.b4
data1.b5

How to initialize Structure ?
struct databits
{
- - -
- - -
}data1 = { 1,1,0,10,234 };
Initialized Result -
data1.b1 = 1
data1.b2 = 1
data1.b3 = 0
data1.b4 = 10
data1.b5 = 234
Diagram :
Bookmark & Share


Tags / Keywords : | , ,

0 comments

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email