A dynamic bitset?

T

tobias.sturn

How would be the best solution to create a dynamic bitset cause with
the stl bitset you have to give a number of how big the bitset will be
and i dont know the size at the beginning...

Thanks very much!!
 
K

Kyle

How would be the best solution to create a dynamic bitset cause with
the stl bitset you have to give a number of how big the bitset will be
and i dont know the size at the beginning...

Thanks very much!!

boost::dynamic_bitset
 
J

John Harrison

How would be the best solution to create a dynamic bitset cause with
the stl bitset you have to give a number of how big the bitset will be
and i dont know the size at the beginning...

Thanks very much!!

vector<bool> is a possibility. Depends exactly what you want to do.

john
 
T

tobias.sturn

vector<bool> would be too big for me... But vector<bitset<32> > is a
possibility
 
A

Andrey Tarasevich

vector<bool> would be too big for me... But vector<bitset<32> > is a
possibility

'std::vector<bool>' is supposed to be specialized as a bit-vector, not as a
plain vector of 'bool' objects, meaning that it will be essentially the same as
your 'vector<bitset<32> >', but with more natural interface. Check your
standard library implementation.
 
T

tobias.sturn

Andrey said:
'std::vector<bool>' is supposed to be specialized as a bit-vector, not as a
plain vector of 'bool' objects, meaning that it will be essentially the same as
your 'vector<bitset<32> >', but with more natural interface. Check your
standard library implementation.

Really?!? But when i had to write convertations from numbers to bits
and from bits to numbers.... Correct?
 
A

Andrey Tarasevich

Really?!?
Yes.

But when i had to write convertations from numbers to bits
and from bits to numbers.... Correct?

Er... Sorry, but I don't understand the question. Can you please clarify?
 
T

tobias.sturn

With bitsets you can make things like:

bitset<32> bits(12);
bits = 4;
int var = bits.to_ulong();

So i can create the bits out of a number. With this bitvectors i had to
write such functions...
 
A

Andrey Tarasevich

With bitsets you can make things like:

bitset<32> bits(12);
bits = 4;
int var = bits.to_ulong();

So i can create the bits out of a number. With this bitvectors i had to
write such functions...

Yes, with 'std::vector<bool>' you'll have to write it yourself or use a
third-party implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top