Learning path

Full curriculum

Full curriculum

Unit content

Boolean values and logic

Many computing decisions reduce to two possibilities: true or false. A Boolean value represents one of these two logical states.

Logical operations

The basic operations are NOT, AND and OR.

NOT reverses a value:

A     NOT A
false true
true  false

AND is true only when both inputs are true, while OR is true when at least one input is true.

A     B     A AND B   A OR B
false false false     false
false true  false     true
true  false false     true
true  true  true      true

Comparisons produce Boolean values

Expressions such as

$$x<10$$

or

$$a=b$$

represent propositions that evaluate to true or false in a given state.

Combining conditions

More complicated conditions are built from simpler ones. For example,

age >= 18 AND has_ticket

is true only when both requirements hold.

De Morgan's laws

Negating a combined condition changes both the operator and the individual terms:

$$\neg(A\land B)=(\neg A)\lor(\neg B),$$

$$\neg(A\lor B)=(\neg A)\land(\neg B).$$

Boolean logic is the foundation of conditions, loops, digital circuits and many forms of program control.