Using Bit fields

Posted on 2002-03-12
Medium Priority
Last Modified: 2010-04-01
  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

Question by:Anisha
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

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

SGI's reference has a good technical description:

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

Expert Comment

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));

Author Comment

ID: 6859968
 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.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 30

Expert Comment

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

Expert Comment

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


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/


Expert Comment

ID: 6979081
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

762 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