|
-
Jan 5th, 2001, 04:12 AM
#1
Thread Starter
Lively Member
Hi,
Can someone explain to me how to perform bit Manipulation and comparison in VB.
I have used it in Delphi, but have never had to in VB until now...
I have an integer field in a DB that has certain bits set to specify certain criteria.
I need to be able to check bits, and set them...
THE DOUGSTER!!!!!!
*-MCSD-*
-
Jan 5th, 2001, 04:43 AM
#2
Addicted Member
Hi
I am assuming that you allready know the basics of binary and hex.
So.....
To do a comparision to check if a single bit in a byte, int or what ever you can use the logical And operator with a bit mask.
To toggle a single bit with in a value you use the Or operator.
i.e. &H7F Or &H80 = &hFF or in other words
0111 1111
OR
1000 0000
=
1111 1111
HTH
Geoff
-
Jan 5th, 2001, 06:08 AM
#3
transcendental analytic
Similary you can use these operators for bit manipulation: Xor or Eqv(to invert bits) And (to set bits to 0) Or (to set bits to 1) Not (to invert all bits) and imp (implication)
You can operate several bits at the same time, since the comparation is bitwise, for instance 11110 and 10101 is 10100.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 5th, 2001, 06:44 AM
#4
Fanatic Member
Note that these operators will work with any numerical values, not just Hex representations... it will cast to an integer type before performing the comparison though so do not bother using fractional parts...
kedaman - What is Imp, never come across that before - looks evil (geddit?)
Cheers,
P.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Jan 5th, 2001, 01:11 PM
#5
transcendental analytic
EVIL! EVIL! EVIL!
Imp.. hehe, nope probably not evil even if it sounds evil. But you probably don't need to use it, there was a thread a while back about the implication operator and it proved to be useful in some special cases
0 imp 0 = 1
0 imp 1 = 1
1 imp 0 = 0
1 imp 1 = 1
false implicates always true, it just skips the second operand, otherways it returns the second operand.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|