std::bitset construction with std::string question

Discussion in 'C++' started by Dill Hole, Jul 4, 2003.

  1. Dill Hole

    Dill Hole Guest

    Can anyone tell me why

    std::bitset<2> foo(std::string("01"))

    initializes the bitset in reverse order, i.e.

    foo[0]=true
    foo[1]=false

    I would expect the bitset to be initialized in string text order.
     
    Dill Hole, Jul 4, 2003
    #1
    1. Advertising

  2. "Dill Hole" <> wrote in message
    news:...
    > Can anyone tell me why
    >
    > std::bitset<2> foo(std::string("01"))
    >
    > initializes the bitset in reverse order, i.e.
    >
    > foo[0]=true
    > foo[1]=false
    >
    > I would expect the bitset to be initialized in string text order.


    I wouldn't,

    6 = 110 = 1*2^2 + 1*2^1 + 0*2^0 == foo[2] is 1, foo[1] is 1, foo[0] is 0.

    In other words its a consequence of the fact that in English numbers the
    most signficant digit goes first.

    john
     
    John Harrison, Jul 4, 2003
    #2
    1. Advertising

  3. Dill Hole

    Mike Wahler Guest

    Dill Hole <> wrote in message
    news:...
    > Can anyone tell me why
    >
    > std::bitset<2> foo(std::string("01"))
    >
    > initializes the bitset in reverse order, i.e.
    >
    > foo[0]=true
    > foo[1]=false
    >
    > I would expect the bitset to be initialized in string text order.


    See John H's reply, then observe the output of:

    cout << foo << '\n';

    -Mike
     
    Mike Wahler, Jul 5, 2003
    #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. SpOiLeR
    Replies:
    5
    Views:
    1,349
    SpOiLeR
    Mar 16, 2005
  2. Gaijinco

    C quivalent of std::bitset

    Gaijinco, Sep 29, 2005, in forum: C Programming
    Replies:
    3
    Views:
    353
    Gaijinco
    Sep 29, 2005
  3. Ook
    Replies:
    10
    Views:
    558
  4. Haro Panosyan

    std::bitset, simple question

    Haro Panosyan, Dec 6, 2005, in forum: C++
    Replies:
    14
    Views:
    1,148
    Haro Panosyan
    Dec 6, 2005
  5. Ninds
    Replies:
    14
    Views:
    749
    W Karas
    Dec 3, 2012
Loading...

Share This Page