Bit Operations using Structure !!!
- To pack Several data objects in the single memory word , Bits are used .
- Flags can be In order to store the Boolean values ( T / F ).
- Eg. Gender of Person can be stored as [M/F] .
- By Setting the flag bit 1 we can set Gender as “Male” and “Female” by setting bit as 0
- 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 :



