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