Tim Buchalka

# Boolean Operators - Learn To Code Series

**In the last post in this series, I posed the question to you: "Do you know what Boolean operations are?" You'll find out the answer to that in this blog. **

Alright, so let's find out now what Boolean operations are. Well, Boolean operations are actually foundational for an understanding of gates, circuits, and switches, and these are the basic building blocks for today's computers. Now, I've covered gates, circuits, and switches in the next blog post in this series, but for now, let's explore what George Boole pioneered over 150 years ago.

Today's computers store everything in binary digits, zeros and ones. To understand how individual bits are stored and manipulated inside a computer, it's convenient to say that the bit zero represents the value false, and the bit one represents the value true. Operations that manipulate true and false values are called Boolean operations in honour of George Boole, a pioneer mathematician of the mid-1800s.

There are seven Boolean operations however, I only need to discuss the basic four: AND; OR; XOR, referred to as Exclusive OR; and NOT to illustrate all of this. Boolean operation names are usually written with capitalized letters to distinguish them from their English counterpart words. These operations are similar to the arithmetic operations times and plus because they combine a pair of values as input to produce a third value as output. For example, three times five, the two input values, equals 15, the output value. Or three plus five equals eight, two inputs resulting in one output.

In contrast to arithmetic operations, however, Boolean operations combine true or false values rather than numeric values as input and produce either a true or false value as its output. The Boolean operation AND reflects the truth or falseness of a statement formed by combining two individual statements together with a conjunction word AND.

Now, a generic form for this Boolean operation statement is as follows, X AND Y. So for example, my brother is older than me AND my sister is younger than me. So the two inputs to this AND Boolean operation are my brother is older than me and my sister is younger than me. The output, either true or false, represents the truth or falseness of the compound statement itself. Now, this may seem complicated as I speak it; however, you and I use compound AND statements in our ordinary conversations every day of our lives and probably don't even realize it.

In the figure below, there are four potential results when using the AND operation. Only one of them outputs a true statement for the compound AND statement. The other three of those say yield with a false result.

So in the brother and sister compound statement, if it's true that my brother is older than me AND if it's true that my sister is younger than me, then the result for the compound statement is true. If my brother is the same age as me or younger than me, then this portion of the compound statement would be false. If my sister were the same age as me or older than me, then this portion of the compound statement would be false.

Based on Boole's logic for the AND, if either part of the compound AND statement is false, or if both parts of a compound AND statement are false, then the entire, or whole, compound statement is false. Again, hearing me say this may seem much more complicated than it really is. Remember that you use compound AND statements every day however, I suspect most (if not all) of your compound statements, result in a true statement.

Referring again to the AND operation in the previous image/figure, the zero represents false and a one represents true. So zero and zero yields a false, zero and one yields a false, one and zero yields a false, and finally one and one, well, that yields a true result. The Boolean operation OR, well, that reflects that truth or falseness of a statement formed by combining two individual statements together with a conjunction word OR. Now a generic form for the Boolean OR operation statement is as follows: X OR Y.

For example, my family pet is a dog OR my family pet is a cat. So the two inputs to this OR Boolean operation are my family pet is a dog and my family pet is a cat. The output, either true or false, represents the truth or falseness of the compound statement itself. Now, once again, this may seem complicated as I speak it; however, you and I use compound OR statements in our ordinary conversations every day of our lives.

For example, your friend asks you what you're going to have for lunch and you respond with, "I think I'll have a taco or a burrito". So notice if you do eat a taco for lunch, the compound OR statement you used is true. If you eat a burrito, the compound OR statement, well that's also true. And if you eat both a taco and a burrito, the compound OR statement, you guessed it, is also true.

Now, if you decide to eat a peanut butter sandwich rather than a taco or burrito, then the compound OR statement is false. So three of the four possible results for a Boolean OR operation yield a true result, and only one is a false result. So referring this time to figure's OR operation as zero, represents false, and a one represents true. So zero and zero yields a false, zero and one yields a true, one and zero, well that yields a true, and then finally, one and one also yields a true result. 0

The third Boolean operation to talk about is the XOR or exclusive OR. So the exclusive OR operation is used when we wanna express that if either of the two parts of the component or statement is true, then the whole component statement is true but not if both parts of the component statement are true. So if that happens, in other words, both parts are true, then the whole compound statement is false. So this logical operation is a bit strange in our real spoken languages; however, it's quite common in computer languages.

Now a generic form for this Boolean operation statement is X XOR Y. Remember, that XOR is exclusive OR. So for example, I like fruit exclusive OR I like nuts on top of my ice cream. So the exclusive OR means that I do not like both fruits and nuts on top of my ice cream at the same time. The exclusive OR also means that I do not like my ice cream without any fruit or nuts being put on top.

Referring to the figure's exclusive OR operation illustration, notice that two of the results are true and the other two are false NOT X, so for example, my brother's name is Ronald. In a Boolean NOT operation, that statement would look something like this: NOT my brother's name is Ronald.

Now that's a bit odd. What the NOT statement will do is determine the truth or falseness of what is inside the parentheses, my brother's name is Ronald, and then reverses that result. So if it's true, then the whole NOT statement results in false. If my brother's name is not Ronald then the whole NOT statement is true. So, again, kind of odd, but very useful in programming languages as you'll see later in this course.

Now, don't worry if you didn't understand some or all of this video, Boolean operators are actually easy to understand, much easier once you start using them in programming code. And just so it's clear, this is not just a theory course. I know that's all we've really focused on so far, but we will be getting to doing some actual real coding later in the course.

Alright, so that's Boolean operations, but what do these operations really have to do with computer gates, circuits, and switches? Well, we'll find out more about that in the next blog. Thanks for reading!