Karla News

Boolean Logic Basics

Boolean logic is used in all sorts of computer programs in many different computer languages. Using Boolean logic programs can be created that can do just about anything that can be imagined, and even things that can not. Search engine, video games and accounting programs are just a few examples of software in our everyday lives that make use of Boolean logic.

Invented by George Boole in 1847, long before computers, (Singha.), Boolean logic started out as a mathematical concept based on two things and only two things, true and false. As Boolean logic evolved into the use of computers, true and false became 1 and 0.

Example of how true and false can be used in code:

If soda = cold Then
do drink soda
Else
put soda in fridge
End If

This statement essentially says, if it is true that the soda is cold, drink it. If it is false that the soda is cold, put it in the fridge.

Basic Theory

As mentioned above, all Boolean logic is based on whether something is true or false, there is no gray area, but there are ways to play with this logic when writing code. The three basic words used when playing with Boolean logic are ‘and’, ‘or’ and ‘not’ (Quirksmode. 2009.). By using these three little words, you can change the outcome of your program.

Example of using an ‘and’ in Boolean logic:

If soda = cold AND soda = has your name written on it Then
do drink soda
Else
put soda in fridge
End If

See also  Microsoft Wireless Optical Notebook Mouse 3000

This statement is saying that in order for you to be able to drink it, it must be both cold and have your name written on it. Otherwise, put it in the fridge.

If I w ere to change the code slightly for the ‘or’ operator, it would look like this:

If soda = cold OR soda = has your name written on it Then
do drink soda
Else
put soda in fridge
End If

This is saying something different than the ‘and’ statement. This is telling you that you can drink the soda if it is cold or has your name on it. It does not have to be both. If it is neither, then you still need to put it in the fridge.

The ‘not’ operator is a little more tricky, it creates an opposite effect. Let us see how this would work:

If NOT soda = cold Then
do drink soda
Else
put soda in fridge
End If

This would mean something like, if the soda is not cold, then you can drink it, otherwise, put it in the fridge. Get it?

Using Boolean Search Engines

Since search engines are built using Boolean logic, you can also perform your searches using Boolean logic. The operators ‘and’, ‘or’ and ‘not’ (Boswell.) can be used to perform searches with most of your favorite search engines as well as the plus (+) and minus (-) sign symbols and parenthesis (“”) (Boswell.). Using these words and symbols can help you refine your searches and better find what you are looking for on the Web.

See also  How to Improve Your Battery Life on an IPod Touch

For instance, if you’re doing a search for dogs but you want dogs that are brown, you would type in dogs +brown. If you want dogs that are not brown, you would type dogs ‘”brown. This will cause the search engine to exclude the word brown from the search altogether, making it so that any search results with the word brown in them will not be shown. Maybe you want to do this; dog +brown ‘”tail, now you are searching for brown dogs without tails.

You would use the parenthesis if you want to search for a phrase. Maybe you want to search for the specific phrase “little brown dog.” You would type the phrase into your search bar exactly like this: “little brown dog”, parenthesis and all. Then all the results that you got back would have that exact phrase on the page somewhere.

Life Without Boolean?

There are so many things that a programmer can do with Boolean logic. Without Mr. Boole who knows if we would have computers or video games today. Maybe someone else would have come up with it, maybe someone would have come up with another way to design computers, who has to say. With this amazing invention, computers and programming have come a long way.

Reference: