Mastering Boolean Expressions
Introduction to Boolean Logic
The Logic of True and False
At its core, a computer doesn't understand words, images, or sounds. It only understands whether a switch is on or off. This simple, two-state system is the foundation of all modern computing, and it's governed by a set of rules called Boolean logic.
Imagine a light switch. It can only be in one of two states: on or off. There's no in-between. Boolean logic works the same way. Every statement or condition is either true or false. In computing, we often represent these states with numbers: 1 for true (on) and 0 for false (off).
Boolean variable
noun
A variable that can only hold one of two possible values: true or false.
These true/false values are the building blocks. A Boolean expression is simply a statement that evaluates to either true or false. For example, the statement "the sky is blue" is true. The statement "pigs can fly" is false. Computers use these expressions to make decisions, from deciding when to show a notification to running complex software.
Basic Logical Operators
To do useful work, we need to combine or modify these true/false values. We do this with logical operators. Think of them as the grammar of Boolean logic. Let's look at the three most basic ones: NOT, AND, and OR.
NOT is the simplest operator. It just flips a value. If something is true, NOT makes it false. If it's false, NOT makes it true.
NOT truebecomesfalse.NOT falsebecomestrue.
If the statement is "The door is closed" (true), applying NOT gives you "The door is not closed" (false).
AND combines two Boolean values. The result is true only if both of the original values are true. If even one is false, the whole expression becomes false.
Imagine you need a driver's license. You must pass the written test AND pass the driving test. If you only do one, you don't get your license. Both must be true.
true AND trueistruetrue AND falseisfalsefalse AND trueisfalsefalse AND falseisfalse
OR also combines two values, but it's less strict. The result is true if at least one of the original values is true. It's only false when both are false.
Think about charging your phone. You can plug it into the wall OR a portable battery. As long as you do at least one of those things, your phone will charge. You don't need to do both.
true OR trueistruetrue OR falseistruefalse OR trueistruefalse OR falseisfalse
These three simple operators—NOT, AND, OR—are the fundamental tools for decision-making in every computer program and digital circuit.
At its most fundamental level, a computer understands information in what form?
The Boolean expression (user is logged in) AND (user has a premium subscription) evaluates to true only if both conditions are met.
