1. Home
  2. Computing & Technology
  3. Visual Basic
Symbolic Logic
Part 3: Mapping Out Symbolic Logic
 More of this Feature
• Part 1: Symbolic Logic
• Part 2: The Basics of Symbolic Logic
• Part 4: Going Behind the Symbolic Logic Mask
• Part 5: Visualize Symbolic Logic
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 
 Related Resources
• Calculating a Contrasting Color Code
The first article in the series. • The Imp Logical Operator
• VB .NET New Logical Operators AndAlso and OrElse
 
 Elsewhere on the Web
• Association for Symbolic Logic
• Karnaugh Maps
• A game for understanding Venn Diagrams
 

Karnaugh Map of And

The result of the And function is 1 (true) if each of its arguments are 1 (true). This means that the result of using a 1 in a bit mask is a 1 in the result if there is a 1 in the other argument as well. In the discussion of Color variables, for example, the part of the Color value that represented green was found by saying Color And &HFF00&. The result of this expression is the part of a Color variable that represents green since only the "green" bits in the mask are 1.

Another handy example is a test to determine if an integer is odd by testing for Number And 1. This will have the value 1 for odd numbers and 0 for even numbers.

Karnaugh Map of Or

Or is 1 (true) if either or both of its arguments are 1 (true). Since it is 1 if either or both of the arguments are 1, it is also called an Inclusive Or, to differentiate it from Xor which we'll discuss next. When used as a mask, a 1 bit in the mask will always create a 1 in the result, but a 0 in the mask will create whatever bit value was in the original. Therefore, Or is usually used as part of a mask to change a selected group of bits to all 1's.

Karnaugh Map of XOr

Xor (Exclusive Or) is 1 (true) if either but not both of its arguments are 1. The masking action of Xor is similar to Or since a 0 in the mask will create whatever bit value was in the original. But a 1 in the mask will reverse the value in the original. Xor is usually used to produce the reverse value in a selected group of bits.

Karnaugh Map of Eqv and Inv

Eqv stands for Equivalence, and is 1 (true) if both of its arguments are 1 (true), or if both of its arguments are 0 (false). As an excercise to understanding Eqv, you can see from the table above that:

p Eqv q

is exactly the same as:

Not (p Xor q)

This, in turn, could be written on one line as:

(p Eqv q) Eqv (Not (p Xor q)) == True

Imp (Implies) is perhaps the least used, and least understood, of the logical operators. p Imp q is 1 (true) whenever either p is 0 (false) or q is 1 (true). That is, Imp is False when p is True and q is False (truth cannot imply falsehood) and is True for all other situations (truth can imply truth, and falsehood can imply either truth or falsehood).

The fact that both Eqv and Imp are used very little probably accounts for the fact that they have been dropped from VB .NET. But VB .NET has implemented improved evaluations of And and Or called AndAlso and OrElse. Since logic is logic and doesn't change, the rules we've been talking about here are the same for AndAlso and OrElse. These new operators are only different in the way VB .NET uses the results of the logic. The new operators are discussed in an About Visual Basic article at this link.

Next page > Going Behind the Symbolic Logic Mask > Page 1, 2, 3, 4, 5
Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.