bitset woes

P

Paul Richardson

I have tried reading all the docs and I suppose I am just not parsing
them correctly so I'll ask here

suppose I have three bitsets as follows:
bitset<48> a;
bitset<48> b;
bitset<48> c:

I want to bit-by-bit and the contents of a and b and have them placed
in c, what does the syntax look like for this. I thought, given that
some of the operators are overloads, that i might look like

c = a &b

this does not work however


Thanks in advance
 
S

stefan.ciobaca

It works for me. I'm using g++

g++ (GCC) 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)

to compile this

<code>
#include <bitset>
#include <iostream>

using namespace std;

int main()
{
bitset<48> a, b, c;

for (int i = 0; i < 48; ++i)
{
b = rand() % 2;
a = rand() % 2;
}
c = a & b;
cout << a << endl << b << endl << c << endl;
}
</code>

What compiler are you using? What exactly doesn't work?
 
P

Paul Richardson

Care to take on the usage of to_string()
It works for me. I'm using g++

g++ (GCC) 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)

to compile this

<code>
#include <bitset>
#include <iostream>

using namespace std;

int main()
{
bitset<48> a, b, c;

for (int i = 0; i < 48; ++i)
{
b = rand() % 2;
a = rand() % 2;
}
c = a & b;
cout << a << endl << b << endl << c << endl;
}
</code>

What compiler are you using? What exactly doesn't work?

Paul said:
I have tried reading all the docs and I suppose I am just not parsing
them correctly so I'll ask here

suppose I have three bitsets as follows:
bitset<48> a;
bitset<48> b;
bitset<48> c:

I want to bit-by-bit and the contents of a and b and have them placed
in c, what does the syntax look like for this. I thought, given that
some of the operators are overloads, that i might look like

c = a &b

this does not work however


Thanks in advance
 

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,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top