Solved

Using Bit fields

Posted on 2002-03-12
6
193 Views
Last Modified: 2010-04-01
Hi!
  I m back again with a another query , before that i must say God bless the team who thought of this site, has helped  me a lot during my studies, i m contributing my bit by recomending it to my friends.
  Getting back to my query, i want to  create a mask for a p'cular color in an image  , now i create this mask by creating a char array of the iamge size and using it for storing 1s for the corresponding color and 0s otherwise. This is not a problem , the problem is that just to store 1 bit data i m using 8bits(byte of a char) , i was suggested to use bit fields but then i cannot create an array of bitfield structure and since the image size varies i cannot predefine it. Please help

Anisha.
0
Comment
Question by:Anisha
6 Comments
 
LVL 4

Accepted Solution

by:
ct.smith earned 100 total points
ID: 6859756
I suggest the STL container bitset.

SGI's reference has a good technical description:
http://www.sgi.com/tech/stl/bitset.html

Most (recent) C++ books should have good code examples of how to use the container.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 6859876
If you want to do it the old-fashioned way you can just allocate your array at one-eighth the size you have it and use shift operations to read and set data--it would be quite easy to write functions to do this for you.

e.g. to set bit 370 in an array: array[370>>3] |= (1 << (370 & 7));
0
 

Author Comment

by:Anisha
ID: 6859968
pjknibbs,
 thanks for the sugestion but i have kept that as an alternative, but i would  really wait and see if someone can help me with bitfields , life will be easier then.

Anisha.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Expert Comment

by:Axter
ID: 6861941
I agree with ct.smith.  You should use the bitset container.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6955346
Dear Anisha

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "ct.smith"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 6979081
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now