[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Shiftable, ANDable bit vector

Johannes Bauer

10/27/2008 1:28:00 PM

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

--
"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$7510$5402220f@news.sunrise.ch>
2 Answers

Mirco Wahab

10/27/2008 1:45:00 PM

0

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

Michael DOUBEZ

10/27/2008 2:13:00 PM

0

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.

--
Michael