Boolean
Boolean
The ASCII
charchaaractcteerrs
set is fixed width and only uses one byte. When encoding afile that uses only ASCII
with UTF-8, the resulting file would be identical to afile encoded with ASCII. Thissiis not
when using UTF-16 as each character would be two bytes long. possible
2.5 BOOLEAN LOGIC
Have you ever wondered how acomputer can do something like balancing a chequebook, or
playing chess or spell-checking a document? These are things that, just a few decades ago, oniy
humans could do. Now, computers do them with much ease. How can a "chip" made up of silicon
and wires do something that seems like it requires human thought?
If you want to know the answer to this question, the first thing you need to understand
something called Boolean logic. Boolean logic was originally developed by George Boole in
the mid-1800s, who figured out a way to put formal logic into mathematical form. Simply put,
Boolean logic is a very easy way to figure out the truth of an expression using the simple concept
of true orfalse.
Consider the following examples:
> Should Igo to a restaurant or not?
Open Closed
(binary 0) (binary 1)
The digit 1 or letter T' is used to represent true value and the digit 0 or letter 'F represents a
false value. Astatement which evaluates either true or false is knownas Proposition (or logical
statement).
CTM: 1 and0 are two binary-valued quantities that represent true or false state.
Boolean Variable
ABoolean variable is also known as binary variable or logical variable that takes its vaue
from Boolean algebra. ABoolean variable can take only one binary-valued quantity ou
the two possible values, ie, yes/no, 1/0, true/false. One bit represents one Boolean var
In electrical circuit, if the signal passes, it represents 1, else it is represented through
Boolean Constant
The values which are stored in binaryvariables are known as Boolean Constants. Therefore,
the values true/false,yes/no or 1/0are Boolean constants.
Boolean Statement: Astatement is said to be a Boolean /Logical Statement if it has adefinite
value which is either false or true.
Examples:
Logical Statement Non-logical Statement
Have you finished your homework? What are your plans for tomorrow?
Is the house locked? Who is the President of India?
Is New Delhi the capital of India? Where is your house located?
Boolean Variable: A variable which holds false/true value is known as Boolean variable.
(X, Y, Z, etc.)
Boolean Expression: Ameaningful combination of Boolean operators (AND/OR/NOT), Boolean
operand/variable (X, Y, Z, etc.) and Boolean constant (0 or 1) is known as Boolean Expression
(Logical Expression). For example,
) X+ Y.Z
(i) A. (B+C) +B.C"
(ii) UOR VAND NOT Z
The AND operation willresult in true value (1) when both inputs are 1 (true/high), and for all
other values it results ín 0 (false/low).
A B A B OUTPUT A+B
1 0 1 1
1 1 1
1 1 1 1 1
The OR operation results in true value (1) when either of the inputs is 1(true) or both the inputs
are 1 (true /high), and for all other values of inputs it results in 0 (false/low).
2.6.3 NOT Operator
The NOT operator is a unary operator that operates on one variable and the operation performed
by NOT operator is known as negation or complementation.
Consider Tables 1 and 2 with values 0and 1 for variable A.
Table 1 Table 2
A A OUTPUT A'
1
1 1
It means that the logicalstatements A and A are opposite to each other. If the value of a variable A
is 0, its complement would be 1, and if the value of the variable A is 1, its complement would
be 0.
Python-X
2.24 Computer Science with
follows:
It can be represented as
A B AvB AB
1 1
1 1 0
1 1 1
If there are three variables A, B and C, then the possible input values will be 23 = 8 combínations.
It can be represented as follows:
A B
1 0
1 1
1 0
1 1
1 1
3. Fill the first half for number of rows with 0's and second half number of rows with 1's in
the first column for variable A. Follow rule nos. 6 and 7 for all other columns for variables
B and C.
A B B A.B' A.B'+C
01
1
L
LU
0 1
1¬
1 1
1 1
4. Perform logical operations B, A.B' and A.B'+C by considering the values 0's and 1's
written in each rowfor each input variable combination andfilling the rows for these
columns with 0's and 1's. The resultant table will be a truth table.
A B C A.B' A.B+C
0 1
1 1 1
1
1 1 0 1
1 1 1
1 1 1
1 1 0
1 1 1 0 1
Python-X
2.26 Computer Science with
o.Write a truth table for the given Boolean Expression: F= A+B.C'+A:C'
Ans. F= A+B.C'+A!C' [Given]
C' A' B.C' A.C' A+B.C' A+B.C'+A.C'
A
0 1 1 1 1
1 1 1 1 1 1 1
1 0
1 1 1 1
1 1
1
1 0 1 1 1
1
1 1 1 1
1
X X.Y' X.Y'+Z
0 0 1
1 1 1
0 1
1 1
0 1 1 1
1
1 1 1 1
1 1
1 1 1 0 1
In this truth table, NOT operation is performed first followed by AND operation and then OR
operation is performed.
2.27
Data Representation and Boolean Logic
Example 13: Prove the following with the help of a truth table:
x.(y+z)-(xy)+ (x:z)
X y+z x.(y+z) X.y X.Z (x.y) + (x.z)
0
0 1 1 0 0
1 1
1 1 1 0
1 0 0 0
1 0 1 1 1 0 1 1
1 1 0 1
1 1 1 1 1 1
CTM: The order of precedence for logical operators is NOT, AND, OR.
NOT Gate
A NOT gate, sometimes called a logical inverter gate to differentiate it from other types of
electronic inverter devices, has only one input. It reverses the logic state. The output state is a
negation or complement of an input signal.
AND Gate
The AND gate is so named because if 0 is called "false" and 1 is called "true," the gate acts in the
same way as the logical "AND" operator. The output is "true" when both the inputs are "true"
Otherwise, the output is "false". AND Gate works on two or more inputs which result in asingle
output.
OR Gate
The OR gate gets its name from the fact that it behaves like logical inclusive "OR" The output is
"true" if either or both of the inputs are "true!" If both inputs are "false" then the output is "alse
OR Gate works on two or more inputs which result in a single output.
Some other important Logic Gates are:
NOR Gate
The NOR gate is a combination of OR gate followed by an inverter NOT gate. Its output is ue
if both the inputs are "false!" Otherwise, the output is "false."
NAND Gate
The NAND gate operates as an AND gate followed by a NOT gate. It acts in the mannerOtherwise.
ot log
operator "'and" followed by negation. The output is "false"if both the inputs are "true"
the output is "true'".
Python
2.28 Computer Science with
XOR Gate
The XOR (exclusive-OR) gate acts in thesame way as
the
ifeither, but not both, of the inputs is "true." The output islogical
"false"
"either/or" The output is "true"
if both the inputs are "false" or
if both the inputs are "true." Another way of
looking at this circuit is to observe that the output
is 1 if the inputs are different, but 0if the inputs are
the same.
The following table shows the truth table and
logic gate of various operators.
Operator Truth Table
Logic Gate
NOT
X X
1
X
1
-ooox
AND X Y X.Y
0
X
0 1
1
-X.Y
0
1 1
OR
X Y X+Y
1 1 -X+Y
1 0 1
1 1 1
1 0 1 Y
1 1 1
1 1 1
XOR X Y XOY
X
1 1 -XOY
1 1 Y
1 1
CTM: The NAND and NOR gates are called universal gates because any digital circuits can be implemented
using these gates.
C
D
o
Q. Write equivalent Boolean expression for the following Logic Circuit:
U
W
Ans. Y = (U.V) +(U.W')
Q. Write equivalent Boolean expression for the following Logic Circuit:
U
V
Z
o
W
Ans. Z = (U'+V).(V'+W)
Duality Principle in Boolean Algebra
This law explains that replacing the variables doesn't change the value of the Boolean function.
The dual of the expressions can be achieved by:
1. Replacing each AND () sign with an OR (+) sign.
2. Replacing each OR (+) sign with an AND () sign.
3. Replacing each variable, such as replacing 1with 0and replacing 0 with 1.
If the operators and variables of an equation or function produce no change in the output of the
equation, though they are interchanged, it is called "Duals".
Q. Find the dual of the following expressions:
() A.B+A.C
Ans. (A+B).(A+C).
(ii) xy + XZ
Ans. (x + ).(x+ z)
Python-N
2.30 Computer Science with
Some Rules/Laws of Boolean Algebra
Law Name AND OR
1 Property of 0 0.A =0 0+A = A
2 Property of 1 1.A =A 1+A =1
3 ldempotent Law A.A = A A+A = A
4
Inverse/Complement Law A.A' =0 A+A'= 1
5 Commutative Law A.B = B.A A+B = B+A
6 Associative Law A.(BC) = (AB).C A+(B+C)=(A+B) +C
7 Distributive Law A+BC = (A+B) (A+C) A(B+C) = AB+AC
Absorption Law A.(A+B) =A A+AB = A
De Morgan's Law AB = A B A+B = A.B
Hence proved.
Hence proved.
Thus, we can say that A+B = A.B
Proof using truth table:
Table 2.5: Truth table
A B A B A+B (A+B)' A.B'
1 1 1 1
1 1 1
1 1 1
1 1 0
A
B Bo A+ B
It is equivalent to:
B
B
D -A. B
The second law states that when two (or more) input variables are AND'ed and negated, they
are equivalent to the OR of the complements of the individual variables.
A.B = A+ B
Let us prove it.
Let P=A.B and P'=(A.B)'
Therefore, P+P'=1 and P.P'=0
(A.B) +(A.B)'=1
=(A.B) +(A+B)
Python-
2.32 Computer Sclence with
=(A+A+B).(B+A+B) [Distributive law]
-(A+A+B).(A+B+B) [Commutative law]
=(1+B).(A+1) [Inverse law]
=1.1
=1
Hence proved.
Thus, we can say that:
A.B = A + B
Proof using truth table:
Table 2.6: Truth table
A B A B A.B (A.B)' A'+B'
1 1 1
0
1 1
1
1 0 1 1 1
1 1 1 0
It is equivalent to:
- +B