using a bitset

Discussion in 'C++' started by Jason, Dec 9, 2003.

  1. Jason

    Jason Guest

    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 :)
    Jason, Dec 9, 2003
    #1
    1. Advertising

  2. Jason

    Bruce Guest

    In comp.lang.c++
    "Jason" <> 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
    Bruce, Dec 9, 2003
    #2
    1. Advertising

  3. Jason

    Jason Guest


    > 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.
    Jason, Dec 9, 2003
    #3
  4. Jason

    Y2KYZFR1 Guest

    "Jason" <> wrote in message news:<br4pb8$gka$>...
    > 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"!
    Y2KYZFR1, Dec 9, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timo Nentwig

    Performance of java.util.BitSet

    Timo Nentwig, Dec 9, 2003, in forum: Java
    Replies:
    4
    Views:
    3,926
  2. Joshua
    Replies:
    4
    Views:
    389
    Esmond Pitt
    May 6, 2005
  3. mathieu

    Using: bitset( string() )

    mathieu, May 6, 2008, in forum: C++
    Replies:
    1
    Views:
    515
    mathieu
    May 6, 2008
  4. Sean Farrow

    using a std::bitset in an iterator

    Sean Farrow, Aug 24, 2008, in forum: C++
    Replies:
    4
    Views:
    937
    Sean Farrow
    Aug 25, 2008
  5. Ninds
    Replies:
    14
    Views:
    740
    W Karas
    Dec 3, 2012
Loading...

Share This Page