Link to home
Start Free TrialLog in
Avatar of Kevin_Elrod
Kevin_Elrod

asked on

Bit manipulation in VB

I am a C++ programmer now learning VB.  Is it possible to do bit manipulation in VB?  I need to call functions in the Win32 API, as well as from my own dll's, that return values that require bit manipulation.
Avatar of DennisBorg
DennisBorg

You can use the AND and OR operators to check or flip bits.

For example:

   Dim Flags As Long

   Flags = &H1A&
   Flags = Flags AND &HF&  
   MsgBox Hex(Flags) '<-- Displays ' A '

   Flags = Flags OR 1
   MsgBox Hex(Flags) '<-- Displays ' B '
There are not any shift operators, but when you shift the bits one position to the left, you are really multiplying by 2. When you shift right, you are dividing by 2.

THe VB operators AND and OR are the LOGICAL equivalents of the C++ operators && and ||


ASKER CERTIFIED SOLUTION
Avatar of johnsand
johnsand

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>THe VB operators AND and OR are the LOGICAL equivalents of the C++ operators && and ||

Actually they're always bit-wise in VB, so they're equivalent to & and |. True is -1, so all bits are set. All numbers are signed in VB.

You've also got Xor, and Not (of course), but unfortunately there isn't a shift or rotate.