bitset woes

Discussion in 'C++' started by Paul Richardson, Jun 18, 2006.

  1. 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
    Paul Richardson, Jun 18, 2006
    #1
    1. Advertising

  2. Paul Richardson

    Guest

    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 Richardson wrote:
    > 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
    , Jun 18, 2006
    #2
    1. Advertising

  3. Care to take on the usage of to_string()
    On 2006-06-18 06:14:23 -0700, said:

    > 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 Richardson wrote:
    >> 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
    Paul Richardson, Jun 18, 2006
    #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,922
  2. Joshua
    Replies:
    4
    Views:
    385
    Esmond Pitt
    May 6, 2005
  3. Dill Hole
    Replies:
    2
    Views:
    435
    Mike Wahler
    Jul 5, 2003
  4. Victor Bazarov

    Re: bitset to UCHAR

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

Share This Page