Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Bit fields

Posted on 2002-03-12
6
Medium Priority
?
244 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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!

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

636 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