using a bitset

J

Jason

hello,

I've been looking into the idea of using a bitset to store a collection of
fields efficiently in a data structure that uses a large number of elements.
My question is what technique is used to extract subsets of the bitset and
use them in normal types? How would i extract bits 3 - 10 inclusive of a
bitset and store them in a char, for example, or how could I go about
treating some bitset elements as a char value or any other atomic data type
for that matter, if that is a better way of wording the question? I know
about the bitwise operators but am not quite sure how to go about achieving
this. Obviously, I am assuming that the STL class bitset really will save
me space and it wont be too slow extracting values rather than using a
structure with bool values, char, long etc as needed, though i am not happy
about how much space that might use.

thanks for any help or advice :)
 
B

Bruce

In comp.lang.c++
Jason said:
I've been looking into the idea of using a bitset to store a collection of
fields efficiently in a data structure that uses a large number of elements.
My question is what technique is used to extract subsets of the bitset and
use them in normal types? How would i extract bits 3 - 10 inclusive of a
bitset and store them in a char, for example, or how could I go about
treating some bitset elements as a char value or any other atomic data type
for that matter, if that is a better way of wording the question? I know
about the bitwise operators but am not quite sure how to go about achieving
this. Obviously, I am assuming that the STL class bitset really will save
me space and it wont be too slow extracting values rather than using a
structure with bool values, char, long etc as needed, though i am not happy
about how much space that might use.

You could answer your questions by looking at bitops.h, bitops.how and
bitarray.c in Snippets.

http://c.snippets.org/browser.php
 
J

Jason

You could answer your questions by looking at bitops.h, bitops.how and
bitarray.c in Snippets.

http://c.snippets.org/browser.php

Thanks but the information in those files is way beyond my basic
understanding of c++. I was hoping for a more dumbed down answer.
Secondly, I want to use the bitset in the stl, not sure if what is in there
is the same or not.
 
Y

Y2KYZFR1

Jason said:
hello,

I've been looking into the idea of using a bitset to store a collection of
fields efficiently in a data structure that uses a large number of elements.
My question is what technique is used to extract subsets of the bitset and
use them in normal types? How would i extract bits 3 - 10 inclusive of a
bitset and store them in a char, for example, or how could I go about
treating some bitset elements as a char value or any other atomic data type
for that matter, if that is a better way of wording the question? I know
about the bitwise operators but am not quite sure how to go about achieving
this. Obviously, I am assuming that the STL class bitset really will save
me space and it wont be too slow extracting values rather than using a
structure with bool values, char, long etc as needed, though i am not happy
about how much space that might use.

thanks for any help or advice :)


"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil."

- Knuth

Outside of micro-embedded programs, which would probably be in C or
ASM and NOT C++ why are you so concerned about such an apparently
trival thing?

Obvioulsy coding it up to work and then profiling it will let you know
if you need to work on it more or that your feared way is "good
enough"!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top