Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Jul 18, 1997

Declaring a bit field for a variable

Question:
Is there a way to explicitly declare the number of bits to allocate to a specific variable? For example, can I declare an integer that would be stored in nine bits?

Answer:
Here is the syntax to define bitfields in C/C++:

struct bitField
{ 
  int a:1; // a has one bit
  int b:7; // b has seven bits
  // .. and so on
};
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date