candidate for bitset

M

ma740988

Given an unsigned int variable that's part of a composite type
struct test {
unsigned int mask;
};

Assume 4 bytes for unsigned int. In one function, I'd like to set
any bit or combination of bits between bits 0 and 23 for the parameter
mask.

So lets suppose I set bits 5, 15 and 23 of mask.

In a separate function I'd like to decode that and store the location
of the bit that was set in a vector .. so in the vector I'd have 5, 15
and 23.

Is this a candidate for bitset? Cant seem to get that to work for me,
then again I'm probably on the wrong track. Trying to determine a way
to make this seemless.

Thanks in advance...
 
V

Victor Bazarov

ma740988 said:
Given an unsigned int variable that's part of a composite type
struct test {
unsigned int mask;
};

Assume 4 bytes for unsigned int. In one function, I'd like to set
any bit or combination of bits between bits 0 and 23 for the parameter
mask.

So lets suppose I set bits 5, 15 and 23 of mask.

In a separate function I'd like to decode that and store the location
of the bit that was set in a vector .. so in the vector I'd have 5, 15
and 23.

Is this a candidate for bitset? Cant seem to get that to work for me,
then again I'm probably on the wrong track. Trying to determine a way
to make this seemless.

Just have fun and implement your own "bitset". What do you think you
can use from std::bitset? 'set' and 'reset'? And std::bitset has no
enumeration, really. So, you'd have to loop over the collection anyway.
Why not challenge your brain to a bit of coding once in a while? :)

V
 
M

ma740988

Happy holidays Vic.
|| Why not challenge your brain to a bit of
|| coding once in a while? :)
Ok
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top