Re: Usisng logical operators with integers in VB

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Bill McCarthy" <Bill@xxxxxxxxxx> wrote in message news:OJEjoQbqIHA.524@xxxxxxxxxxxxxxxxxxxxxxx
Hi Werden,

The And operator and Or operators are bitwise. As well there's the Xor and Not operators. But as to a greater than operator that is bitwise, I actually have never heard of such a thing.

So that if A = 3 and B = 9 then result would be 2.

I don't get this. 3 would be in bits 0011, while 9 would be 1001, so how would you get 2 ?

Maybe A Xor (A And B) ?




okay. Using Tom's options enum

Option1 = &H1
Option2 = &H2
Option3 = &H4
Option4 = &H8

Say I had Option1 (&H1) and Option2 (&H2) set to true for a record (A) in a table, the integer would be stored as 3. Now I add a new record (B) and it has Option1 and Option4 (&H8) set to true so it's stored as 9. *But* although I want to store multiple settings, I don't want have duplicate settings across these records, so I need to remove the Option 1 from the record A.

A B = New A Value
0 1 = 0
0 0 = 0
1 0 = 1
1 1 = 0

So that A now equals 0010 or 2, B is still 1001 or 9 and now don't have any duplicate options set.


I ended up just making a function to do it like this..

Shared Function logical_A_GreaterThan_B(ByVal A As Integer, ByVal B As Integer) As Integer

Dim i As Integer
Dim n As Integer

For i = 0 To 30 ' 2^31 overflows an integer by 1 so let's just do the first 30 bits

n = CInt(2 ^ i)

If CBool(A And n) Then 'if bit in A is 'on'
If CBool(B And n) Then 'if bit in B is 'on'
A -= n 'Turn bit in A 'off'
End If
End If

Next

Return A

End Function


.



Relevant Pages

  • Re: Usisng logical operators with integers in VB
    ... As well there's the Xor and Not operators. ... *But* although I want to store multiple settings, I don't want have duplicate settings across these records, so I need to remove the Option 1 from the record A. ... any duplicate options set. ... Dim i As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Usisng logical operators with integers in VB
    ... As well there's the Xor and Not operators. ... although I want to store multiple settings, I don't want have duplicate settings across these records, so I need to remove the Option 1 from the record A. ... any duplicate options set. ... Dim i As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • AES Implementation
    ... Private Nk As Integer ... Public Sub New ... Dim round As Integer = 1 ... gfmultby03) Xor gfmultby01) Xor ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: True = -1 ?
    ... > I can't for the life of me understand why he continues to call VB's AND, OR, ... If VB supported logical AND, OR, XOR, etc. operators, then it ... Individual gates typically act on individual bits.... ... VB's logical operations yield numerical results based on bitwise comparisons. ...
    (microsoft.public.vb.general.discussion)
  • Re: Bitwise AND causes overflow
    ... bitwise operation to just work blindly on its bits. ... whose internal representation would render the ... Private Type Typea ... Dim a As Typea ...
    (microsoft.public.vb.general.discussion)