Solved

Using Bit fields

Posted on 2002-03-12
6
217 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.
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.

775 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