
is there a way to turn a regular (unsigned long) integer into bitset? for example, unsigned long int a=1234567890; boost::dynamic_bitset<> b(32); can I do something similar to boost::dynamic_bitset<> b(32, a); or b |= a; without resorting to xxxUL etc? at the moment I am doing for( int i=0 ; i< 32 ; i++ ) if( (a & (1UL << i) ) ) b.set(i); Thanks

On Tue, 20 Jun 2006 16:48:32 -0700, "Dr MaaTt" <dr.maatt@gmail.com> wrote:
is there a way to turn a regular (unsigned long) integer into bitset? for example, unsigned long int a=1234567890; boost::dynamic_bitset<> b(32);
can I do something similar to boost::dynamic_bitset<> b(32, a);
Yes, there's a constructor for that: <http://www.boost.org/libs/dynamic_bitset/dynamic_bitset.html#constructors> For portability, you might want to use numeric_limits<> to find out the width in bits of unsigned long. --Gennaro.
participants (2)
-
Dr MaaTt
-
Gennaro Prota