Data representation - EduqasBoolean operators

Binary data can represent numbers, graphics, sound and characters. It is then organised and manipulated differently. Data can also be stored in arrays, records or external files and go through validation or verification checks to ensure accuracy.

Part ofComputer ScienceUnderstanding Computer Science

Boolean operators

Boolean operators are used to connect and compare the relationship between . The result will be either TRUE or FALSE.

Boolean operationOperatorExample
Both statements must be true for the argument as a whole to be true.
AND
if x>=5 AND x <=20
Returns
TRUE
if
x
is any number between 5 and 20.
Only one of the statements needs be true for the argument as a whole to be true.
OR
if x==2 OR x==5
Returns
TRUE
if
x
is either 2 or 5.
The opposite of the argument is true.
NOT
if NOT(x==10)
Returns
TRUE
if
x
is not 10.
The argument is false if both statements are true. The argument is false if both statements are false. Otherwise the argument is true.
XOR
if x<=10 XOR y<=10
Returns
TRUE
if one of
x
or
y
is greater than 10 and the other is not.
Boolean operationBoth statements must be true for the argument as a whole to be true.
Operator
AND
Example
if x>=5 AND x <=20
Returns
TRUE
if
x
is any number between 5 and 20.
Boolean operationOnly one of the statements needs be true for the argument as a whole to be true.
Operator
OR
Example
if x==2 OR x==5
Returns
TRUE
if
x
is either 2 or 5.
Boolean operationThe opposite of the argument is true.
Operator
NOT
Example
if NOT(x==10)
Returns
TRUE
if
x
is not 10.
Boolean operationThe argument is false if both statements are true. The argument is false if both statements are false. Otherwise the argument is true.
Operator
XOR
Example
if x<=10 XOR y<=10
Returns
TRUE
if one of
x
or
y
is greater than 10 and the other is not.

These can also be combined, for example:

If (x AND y) OR (NOT C)

Truth tables

are a way of showing all the possible outputs for inputs in a logical expression. , used in electronics and therefore computer circuits, are based on truth tables. More complex expressions can combine several inputs and outputs. In the following tables, 1 means TRUE and 0 means FALSE.

AND truth table

ABOutput
000
010
100
111
A0
B0
Output0
A0
B1
Output0
A1
B0
Output0
A1
B1
Output1

In an AND truth table, the output is only TRUE if both inputs are also TRUE.

OR truth table

ABOutput
000
011
101
111
A0
B0
Output0
A0
B1
Output1
A1
B0
Output1
A1
B1
Output1

In an OR truth table, the output is TRUE if any of the inputs are TRUE.

NOT truth table

AOutput
01
10
A0
Output1
A1
Output0

A NOT truth table reverses the input value.

XOR truth table

ABOutput
000
011
101
110
A0
B0
Output0
A0
B1
Output1
A1
B0
Output1
A1
B1
Output0

In an XOR truth table, the output is TRUE if only one of the input values is TRUE.

Boolean notation

Logical expressions can also be expressed using Boolean algebra notation. Instead of writing the words AND, OR, NOT or XOR it is often written using the following shorthand notation.

Boolean expressionShorthand notation
A AND BA . B
A OR BA + B
NOT AA’ (can be also shown as Ā)
A XOR BA ⊕ B
Boolean expressionA AND B
Shorthand notationA . B
Boolean expressionA OR B
Shorthand notationA + B
Boolean expressionNOT A
Shorthand notationA’ (can be also shown as Ā)
Boolean expressionA XOR B
Shorthand notationA ⊕ B

Boolean identities and rules

RuleAND formOR form
Commutative lawA . B = B . AA + B = B + A
Associative law(A . B) . C = A . (B . C)(A + B) + C = A + (B + C)
Distributive law(A . B) + C = (A + C) . (B + C)(A + B) . C = (A . C) + (B . C)
Identity lawA . 1 = AA + 0 = A
Zero and one lawA . 0 = 0A + 1 = 1
Inverse lawA . A’ = 0A + A’ = 1
Idempotent lawA . A = AA + A = A
Absorption lawA . (A + B) = AA + A . B = A A + A’ B = A + B
Double complement lawĀ = A
RuleCommutative law
AND formA . B = B . A
OR formA + B = B + A
RuleAssociative law
AND form(A . B) . C = A . (B . C)
OR form(A + B) + C = A + (B + C)
RuleDistributive law
AND form(A . B) + C = (A + C) . (B + C)
OR form(A + B) . C = (A . C) + (B . C)
RuleIdentity law
AND formA . 1 = A
OR formA + 0 = A
RuleZero and one law
AND formA . 0 = 0
OR formA + 1 = 1
RuleInverse law
AND formA . A’ = 0
OR formA + A’ = 1
RuleIdempotent law
AND formA . A = A
OR formA + A = A
RuleAbsorption law
AND formA . (A + B) = A
OR formA + A . B = A A + A’ B = A + B
RuleDouble complement law
AND formĀ = A

Examples:

A AND A = A

How?

If A is 0, then the expression is 0 AND 0 = 0, which is equal to A.

If A is 1, then the expression is 1 AND 1 = 1, which is equal to A.

A OR A = A

How?

If A is 0, then the expression is 0 OR 0 = 0, which is equal to A.

If A is 1, then the expression is 1 OR 1 = 1, which is equal to A.

A AND NOT A = 0

How?

If A is 1, then NOT A = 0.

Then the expression becomes 1 AND 0 = 0.

If A is 0, then NOT A = 1.

Then the expression becomes 0 AND 1 = 0.

Simplifying Boolean expressions

You may be asked to simplify a Boolean expression, for example:

X = A AND B OR A AND NOT B

X = A AND (B OR NOT B)

X = A AND 1

X = A