Shiftable, ANDable bit vector

J

Johannes Bauer

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<12> x, 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
 
M

Mirco Wahab

Johannes said:
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<12> x, 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<12> x, 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
 
M

Michael DOUBEZ

Johannes Bauer a écrit :
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<12> x, 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?

std::valarray seems to implements the operations you look for.
If your need intensive computations, look for the equivalent in Blitz.
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top