bit setting

F

fd123456

Tom,

MWells is right, this is the .Net way of manipulating bits. Besides,
your question was rather ambiguous :

Did you mean "are there any functions in the framework that resemble
the "bittest", "bitset" syntax I'm used to", or "How shall I go about
writing a sub to test/set bits"?

In the first case : no, there aren't.
In the second case : you should either use the BitArray class or go
through bitwise operators and powers of two.
bitset(a,2) : a = a & (2 ^ 1) for instance. There are lots of ways to
do this.

Also remember that if it's the extra typing you're worried about, you
can write your own BitTest, etc., methods that encapsulate BitArray
functions, once and for all.

Michel

 
T

tshad

fd123456 said:
Tom,

MWells is right, this is the .Net way of manipulating bits. Besides,
your question was rather ambiguous :


Did you mean "are there any functions in the framework that resemble
the "bittest", "bitset" syntax I'm used to", or "How shall I go about
writing a sub to test/set bits"?

In the first case : no, there aren't.
In the second case : you should either use the BitArray class or go
through bitwise operators and powers of two.
bitset(a,2) : a = a & (2 ^ 1) for instance. There are lots of ways to
do this.

Also remember that if it's the extra typing you're worried about, you
can write your own BitTest, etc., methods that encapsulate BitArray
functions, once and for all.

Actually, that was what I did.

sub bitSet(byRef bitWord as Integer, bit as integer)
bitWord = bitWord or (2 ^ bit)
end sub

sub bitClr(byRef bitWord as Integer, bit as Integer)
if (bitWord and (2^bit)) then
bitWord = bitWord xor (2^bit)
end if
end sub

Function BitTest(bitWord as Integer,bit as integer) As Boolean
BitTest = bitWord and (2^bit)
end function

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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top