An Explanation of Boolean Logic

Introduction
Boolean Operators in Different Programming Code
Boolean Gates



Boolean logic is a subject that I have found is not explained well in programming books or classes. Experienced programmers use the term "Boolean" quite easily, while its meaning may be a mystery to others.

The term Boolean or simply BOOL is named for a 19th century mathematician named George Boole. Boole is recognized for applying concepts of algebra to human logic. Boole moved concepts of human thought process away from the metaphysical or abstract logic of Aristotle to more tangible mathematical principles. The development of concepts we take for granted, like telephone switching and artificial intelligence, are credited to George Boole.

If you have ever taken a True or False test, you have used Boolean logic. In the Boolean system an object can exist in only one of two states, there is no third choice, no maybe or transitional faze. Night and day, black or white. This is a central concept in programming. A simple example is below:

You have four dollars in your pocket. You see a magazine that costs six dollars. Can you buy the magazine?

In a programming context, the question might look like this:

money = 4
if money is more or equal to 6, say "I can buy the magazine!"
else, say "I can't buy the magazine."

Coded, it might look like this:

integer money;
money = 4;
if(money >= 6){
print "I can buy the magazine!";
}
else{
print "I can't buy the magazine.";
}



What are the different Boolean Operators?

Depending on code being used the operators come with different names and use. Some languages support more Boolean Operators, some less. However, there are some basic standard operators. The result of any Boolean operation should be a TRUE or FALSE.

AND

Two or more items must agree(be evaluated to the same result) for the expression to be true.
1 AND 1 would evaluate to TRUE

0 AND 1 would evaluate to FALSE

1 AND 0 would evaluate to FALSE

0 AND 0 would evaluate to FALSE

1 AND 1 AND 1 would evaluate to TRUE

1 AND 1 AND 0 would evaluate to FALSE


OR

One, both or more items must agree. If both inputs are FALSE, the result it FALSE.
1 OR 1 would evaluate to TRUE

0 OR 1 would evaluate to TRUE

0 OR 0 would evaluate to FALSE


NOT

Reverses the input. If TRUE is input, the result id FALSE; if FALSE is input, the result is TRUE.
1 would evaluate to FALSE

0 would evaluate to TRUE


XOR (eXclusive OR)

Only one input may be TRUE, if both are TRUE the entire result id FALSE.
1 XOR 1 would evaluate to FALSE

1 XOR 0 would evaluate to TRUE

0 XOR 1 would evaluate to TRUE

0 XOR 0 would evaluate to FALSE


NAND (Not AND)

1 NAND 1 would evaluate to FALSE

1 NAND 0 would evaluate to TRUE

0 NAND 0 would evaluate to TRUE

0 NAND 1 would evaluate to TRUE





Boolean Operators, Or Logical Operators, in various code

In Assembler

AND AND
OR OR
XOR Exclusive OR
NOT NOT
TEST Tests for zero bits in an specified operand


In C

&& AND
|| OR
! NOT


In C++

&& AND
|| OR
! NOT


In COBOL

ANDAND
OROR
NOTNOT


In DOS Batch Files

IF EXIST
IF NOT EXIST


In Java

& Boolean AND
| Boolean OR
! Boolean NOT
&& Conditional NOT
|| Conditional OR
^ Boolean Exclusive OR
?: Boolean ANY
boolean Reseved Data Type


In Lisp

(AND) AND
(OR) OR
(NOT) NOT
(COND) Allows you to create your own conditional satement


In SQL

NOT NOT
AND AND
OR NOT
LIKE Allow you to seach for a list containing a string or character. If you wanted names that start with "M" ir would be LIKE 'M%'
NOT LIKE Does the oposite of LIKE, excludes items you do not want in your search


In Perl

&&AND
||OR
!NOT
^Exclusive OR
eqEquality in string comparison not for numeric values,
if used for numeric values it will treat them as strings and add up the ASCII values.
neInequality in string comparison not for numeric values,
if used for numeric values it will treat them as strings and add up the ASCII values
==Numeric equality
!=Numeric inequality
andLow-precedence AND
orLow-precedence OR
notLow-precedence NOT
xorLow-precedence Exclusive OR


In Abel

!NOT
&AND
#OR
$XOR
!$XNOR



Boolean Gates

Learning about Boolean Gates(or Logic Gates) is key to understanding computer internals. Logic gates are graphic represntations of what exists within computer memory, microprocessors and other logic devices. This section is not yet done, so I suggest one of these:

http://www.ece.utexas.edu/~jharper/gates.html
http://www.howstuffworks.com/boolean.htm
http://educ.queensu.ca/~compsci/resources/BoolLogic/titlepage.html