
- Forum
- Programming Talk
- C and C++
- Bit fields in c++
Bit fields in c++
This is a discussion on Bit fields in c++ within the C and C++ forums, part of the Programming Talk category; hello.. this is srini... is any one clear me the concept of BIT FIELDS........and what is necessity to use????? explain ...
-
03-03-2010, 09:51 AM #1
- Join Date
- Feb 2010
- Answers
- 3
Bit fields in c++
hello..
this is srini... is any one clear me the concept of BIT FIELDS........and what is necessity to use?????
explain the below program..........i hope i can get a good reply from the great members
// BIT FILED //
#include<iostream.h>
#include<conio.h>
struct word
{
unsigned w0:1,w1:1,w2:1,w3:1,w4:1,w5:1,w6:1,w7:1,w8:1,w9:1,w10:1,w11:1,w12:1,w13:1,w14:1,w15:1,w16:1,w17:1,w18:1,w19:1,w20:1,w21:1,w22:1,w23:1,w24:1,w25:1,w26:1,w27:1,w28:1,w29:1,w30:1,w31:1;
};
union set
{
word m;
unsigned u;
};
void main()
{
set x,y;
x.u=0x0f100f10;
y.u=0x01a1a0a1;
x.u=x.u|y.u;
cout<<"element 9="<<((x.m.w9)?"true":"false")<<endl;
}
OUTPUT
ELEMENT 9 =TRUE

-
03-13-2010, 04:57 AM #2
- Join Date
- Feb 2010
- Answers
- 4
- They can only be declared inside a structure or a union, and allow you to
specify some very small objects of a given number of bits in length.
- Bit fields do not have address.
- We can use bit fields only inside a structure or union.
- Bit fields are used to specify the width of the fields in bits.
- For more details visit the following link.
The C Book — Bitfields
publications.gbdirect.co.uk/c_book/chapter6/bitfields . html

Reply With Quote





