Search This Blog

Sunday, 20 October 2013

Boolean operators

In 1847, British mathematician George Boole proposed a system of algebra that could be used to manipulate proposi-tions, that is, assertions that could be either true or false. In his system, called propositional calculus or Boolean Alge-bra, propositions can be combined using the “and” and “or”
operators (called Boolean operators), yielding a new propo-sition that is also either true or false. For example:

“A cat is an animal” AND “The sun is a star” is true because both of the component propositions are true.

“A square has four sides” AND “The Earth is flat” is false because only one of the component propositions is true.

However “A square has four sides” OR “The Earth is flat” is true, because at least one of the component proposi-tions is true.

A chart called a truth table can be used to summarize the AND and OR operations. Here 1 means true and 0 means false, and you read across from the side and down from the top to see the result of each combination.


AND table

 
0 1   
0 0 0   
1 0 1   
  
OR table   
  
0 1   
0 0 1   
1 1 1   
 

A variant of the OR operator is the “exclusive OR,” sometimes called “XOR” operator. The XOR operator yields a result of true (1) if only one of the component propositions is true:

XOR table

 
0 1   
0 0 1   
1 1 0   
 

Additionally, there is a NOT operator that simply reverses the truth value of a proposition. That is, NOT 1 is 0 and NOT 0 is 1.

Applications

Note the correspondence between the two values of Boolean logic and the binary number system in which each digit can have only the values of 1 or 0. Electronic digital computers are possible because circuits can be designed to follow the rules of Boolean logic, and logical operations can be har-nessed to perform arithmetic calculations.

Besides being essential to computer design, Boolean operations are also used to manipulate individual bits in memory (see bitwise operations), storing and extracting information needed for device control and other purposes. Computer programs also use Boolean logic to make deci-sions using branching statements such as If and loop state-ments such as While. For example, the Basic loop

While (Not Eof()) OR (Line = 50)

Read (Line$)

Print (Line$)

Line = Line + 1

Endwhile

will read and print lines from the previously opened file until either the Eof (end of file) function returns a value of True or the value of Line reaches 50. (In some programming languages different symbols are used for the operators. In C, for example, AND is &&, OR is ||, and NOT is !.)

Users of databases and Web search engines are also familiar with the use of Boolean statements for defining search criteria. In many search engines, the search phrase “computer science” AND “graduate” will match sites that have both the phrase “computer science” and the word “graduate,” while sites that have only one or the other will either not be listed or will be listed after those that have both (see search engine).

No comments:

Post a Comment