bit setting

T

tshad

Is there an easy way to set a bit and clear a bit using a sub - something
like:

bitset(a,2) <-- sets 2nd bit in word
bitclr(a,5) <-- clears 5th bit in word
bittst( a,10) <-- test the 10th bit to see if it is set

I can create these myself, but wondered if there is already and easy way to
do this.

Thanks,

Tom
 
M

MWells

Take a look at System.Collections.BitArray. You can reference and change
individual bits using an index easily.
 
T

tshad

MWells said:
Take a look at System.Collections.BitArray. You can reference and change
individual bits using an index easily.

What I am trying to do is take an integer (that will allow me up to 32
values) and set bits for selections that are made where the selections can
be one selection or multiple selections.

For example, I have 20 possible selections and the user can pick any
combination of choices (1, 4, 5, 12, 17 and 19) could be chosen. I would
then store this word into my database and later can tell which choices were
made.

Why would it be easier to use the System.Collections.BitArray than just to
"and", "or" and "xor" the values?

You still need to do all the same with the bitarrays. But you need to
create bitarray and load it to work with it.

Thanks,

Tom
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top