Shiftable, ANDable bit vector

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johannes Bauer

    Shiftable, ANDable bit vector

    Hello group,

    I need a bit vector of a fixed size (which may well be known at
    compiletime). The requirement is that it should be able to perform the
    &, ^, |, ~ and <</>operations. I.e. something like (pseudocode):

    dreamvector<12x , y, z;

    x[0] = true;
    x[4] = true;
    x[8] = true;
    y[4] = true;

    z = x & y;
    z <<= 3;

    Which should result in z being:

    CBA9876543210
    0000010000000

    Is something like this already present in the STL or do I have to
    implement it by myself?

    Kind regards,
    Johannes

    --
    "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
    verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
    -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
    <48d8bf1d$0$751 0$5402220f@news .sunrise.ch>
  • Mirco Wahab

    #2
    Re: Shiftable, ANDable bit vector

    Johannes Bauer wrote:
    Hello group,
    >
    I need a bit vector of a fixed size (which may well be known at
    compiletime). The requirement is that it should be able to perform the
    &, ^, |, ~ and <</>operations. I.e. something like (pseudocode):
    >
    dreamvector<12x , y, z;
    >
    x[0] = true;
    x[4] = true;
    x[8] = true;
    y[4] = true;
    >
    z = x & y;
    z <<= 3;
    >
    Which should result in z being:
    >
    CBA9876543210
    0000010000000
    >
    Is something like this already present in the STL or do I have to
    implement it by myself?
    Write

    ...
    #include <bitset>
    #define dreamvector std::bitset
    ...

    in front of your code.


    It should read now:

    ....
    #include <iostream>
    #include <bitset>

    #define dreamvector std::bitset

    int main()
    {
    dreamvector<12x , y, z;

    x[0] = true;
    x[4] = true;
    x[8] = true;
    y[4] = true;

    z = x & y;
    z <<= 3;

    std::cout << z << std::endl;

    return 0;
    }
    ....


    Regards

    Mirco

    Comment

    Working...