candidate for bitset

Discussion in 'C++' started by ma740988, Dec 14, 2005.

  1. ma740988

    ma740988 Guest

    Given an unsigned int variable that's part of a composite type
    struct test {
    unsigned int mask;
    };

    Assume 4 bytes for unsigned int. In one function, I'd like to set
    any bit or combination of bits between bits 0 and 23 for the parameter
    mask.

    So lets suppose I set bits 5, 15 and 23 of mask.

    In a separate function I'd like to decode that and store the location
    of the bit that was set in a vector .. so in the vector I'd have 5, 15
    and 23.

    Is this a candidate for bitset? Cant seem to get that to work for me,
    then again I'm probably on the wrong track. Trying to determine a way
    to make this seemless.

    Thanks in advance...
     
    ma740988, Dec 14, 2005
    #1
    1. Advertising

  2. ma740988 wrote:
    > Given an unsigned int variable that's part of a composite type
    > struct test {
    > unsigned int mask;
    > };
    >
    > Assume 4 bytes for unsigned int. In one function, I'd like to set
    > any bit or combination of bits between bits 0 and 23 for the parameter
    > mask.
    >
    > So lets suppose I set bits 5, 15 and 23 of mask.
    >
    > In a separate function I'd like to decode that and store the location
    > of the bit that was set in a vector .. so in the vector I'd have 5, 15
    > and 23.
    >
    > Is this a candidate for bitset? Cant seem to get that to work for me,
    > then again I'm probably on the wrong track. Trying to determine a way
    > to make this seemless.


    Just have fun and implement your own "bitset". What do you think you
    can use from std::bitset? 'set' and 'reset'? And std::bitset has no
    enumeration, really. So, you'd have to loop over the collection anyway.
    Why not challenge your brain to a bit of coding once in a while? :)

    V
     
    Victor Bazarov, Dec 14, 2005
    #2
    1. Advertising

  3. ma740988

    ma740988 Guest

    Happy holidays Vic.
    || Why not challenge your brain to a bit of
    || coding once in a while? :)
    Ok
     
    ma740988, Dec 14, 2005
    #3
    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,974
  2. Joshua
    Replies:
    4
    Views:
    395
    Esmond Pitt
    May 6, 2005
  3. Dill Hole
    Replies:
    2
    Views:
    442
    Mike Wahler
    Jul 5, 2003
  4. Victor Bazarov

    Re: bitset to UCHAR

    Victor Bazarov, Jul 8, 2003, in forum: C++
    Replies:
    1
    Views:
    561
    voger
    Jul 8, 2003
  5. Ninds
    Replies:
    14
    Views:
    792
    W Karas
    Dec 3, 2012
Loading...

Share This Page