Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > using a bitset

Reply
Thread Tools

using a bitset

 
 
Jason
Guest
Posts: n/a
 
      12-09-2003
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



 
Reply With Quote
 
 
 
 
Bruce
Guest
Posts: n/a
 
      12-09-2003
In comp.lang.c++
"Jason" <(E-Mail Removed)> wrote:

>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

 
Reply With Quote
 
 
 
 
Jason
Guest
Posts: n/a
 
      12-09-2003

> 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.


 
Reply With Quote
 
Y2KYZFR1
Guest
Posts: n/a
 
      12-09-2003
"Jason" <(E-Mail Removed)> wrote in message news:<br4pb8$gka$(E-Mail Removed)>...
> 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"!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bitset<32> and bitset<64> efficiency Ninds C++ 14 12-03-2012 11:02 PM
using a std::bitset in an iterator Sean Farrow C++ 4 08-25-2008 08:10 PM
Using: bitset( string() ) mathieu C++ 1 05-06-2008 11:52 AM
Is 'java.util.BitSet' available at JDK1.3? Joshua Java 4 05-06-2005 11:54 AM
Performance of java.util.BitSet Timo Nentwig Java 4 12-11-2003 12:43 AM



Advertisments