Groups | Blog | Home
all groups > asp.net > january 2005 >

asp.net : bit setting


tshad
1/23/2005 11:12:28 PM
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

tshad
1/24/2005 8:29:40 AM
[quoted text, click to view]

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
[quoted text, click to view]

MWells
1/24/2005 9:26:29 PM
Take a look at System.Collections.BitArray. You can reference and change
individual bits using an index easily.


[quoted text, click to view]

AddThis Social Bookmark Button