Solved

Using Bit fields

Posted on 2002-03-12
6
230 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
[X]
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
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
Technology Partners: 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

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

Industry Leaders: 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!

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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

696 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