creating an int from bits

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michiel Salters

    #16
    Re: creating an int from bits

    "Siemel Naran" <SiemelNaran@RE MOVE.att.net> wrote in message news:<8p9nc.330 71$Ut1.947798@b gtnsc05-news.ops.worldn et.att.net>...
    [color=blue]
    > Also, on some systems unsigned may be 16 bits, whereas the OP wants 18.
    > Then std::bitset is good. How slow is it really?[/color]

    Depends on the implementation of course, but it's a template. That means
    that bitset<N> with N<=(bits in int) probably is implemented as an

    class __small_bitset_ impl {
    unsigned int bits;
    protected:
    // all the usual bitset ops, inlined
    };
    template< bool Small, int N>
    class __bitset_impl {
    // usual impl with arrays of ints
    };
    template< int N >
    class __bitset_impl<f alse, N> : public __small_bitset_ impl { };

    E.g. for N<=32 or N<=16 (as appropriate) bitset is just a set of
    inlined utility functions around the same int you would use. Of
    course, an even better version might use some non-portable
    assembly so it could be even better.

    My advise? typedef, initially to std::bitset<18> until profiling
    tells you otherwise.

    Regards,
    Michiel Salters

    Comment

    • Jacques Labuschagne

      #17
      Re: creating an int from bits

      Michiel Salters wrote:[color=blue]
      > Use an unsigned long, it mus always have 32 bits. signed long[/color]

      Really? Tell that to my 64-bit sun box. :-)

      Jacques.

      Comment

      • Default User

        #18
        Re: creating an int from bits

        Jacques Labuschagne wrote:[color=blue]
        >
        > Michiel Salters wrote:[color=green]
        > > Use an unsigned long, it mus always have 32 bits. signed long[/color]
        >
        > Really? Tell that to my 64-bit sun box. :-)
        >[/color]


        You believe that something with 64 bits does not also have 32 bits?

        He did not say that an unsigned long is EXACTLY 32 bits, he said it HAS
        32 bits.



        Brian Rodenborn

        Comment

        • Siemel Naran

          #19
          Re: creating an int from bits

          "Michiel Salters" <Michiel.Salter s@logicacmg.com > wrote in message
          [color=blue]
          > Use an unsigned long, it mus always have 32 bits. signed long
          > also has 32 bits, but one of them is a a sign bit. That[/color]

          Where in the standard does it say long is 32 or more bits?


          Comment

          • David Harmon

            #20
            Re: creating an int from bits

            On Tue, 11 May 2004 03:33:16 GMT in comp.lang.c++, "Siemel Naran"
            <SiemelNaran@RE MOVE.att.net> wrote,[color=blue]
            >"Michiel Salters" <Michiel.Salter s@logicacmg.com > wrote in message
            >[color=green]
            >> Use an unsigned long, it mus always have 32 bits. signed long
            >> also has 32 bits, but one of them is a a sign bit. That[/color]
            >
            >Where in the standard does it say long is 32 or more bits?[/color]

            It's adopted from the C standard, wherein it says that ULONG_MAX must be
            greater or equal to 4294967295, etc. (the calculation of the number of
            bits required is left to the information theory student. But see

            )

            Comment

            Working...