﻿'Visual Basic 2012 Logische Bitsgewijze Operatoren Operatoren Module LogicalBitwiseOperatorsExample1 Sub Main() Console.WriteLine(7 And 10) Console.WriteLine(7 Or 10) Console.WriteLine(7 Xor 10) ' Console.WriteLine(7 And Not 7) ' Console.ReadLine() End Sub End Module Module LogicalBitwiseOperatorsExample2 Sub Main() Dim tamagotchiState As Integer = 5 ' ... If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") ' (1) If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi not hungry ...") tamagotchiState = tamagotchiState And Not 4 ' (2) Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi thirsty ...") tamagotchiState = tamagotchiState Or 2 ' (3) Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi happy, hungry and tired ...") tamagotchiState = tamagotchiState Or 1 Or 4 Or 8 Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi not hungry and not tired ...") tamagotchiState = tamagotchiState And Not 4 And Not 8 Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("inverting states ...") tamagotchiState = Not tamagotchiState Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") ' Console.ReadLine() End Sub End Module 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2012 - Alle rechten voorbehouden.