0% found this document useful (0 votes)
4 views

Boolean

Uploaded by

Anshika Bhardwaj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Boolean

Uploaded by

Anshika Bhardwaj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

The main advantage of UTF-8 is that it is backward compatible with ASCII.

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?

Should Ipurchase a new mobile phone or not?


Should I opt for Computer Science or not?
All these questions can have only one answer, either in the form of yes or no. Thus, a binary
decision always results in either yes/no or true/false. Likewise, a switch has only two states
open and closed. An open switch represents binary 0 and a closed switch represents binary 1.

Open Closed
(binary 0) (binary 1)

Fig. 2.6: Showing Open and Closed Switch

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

2.6 BOOLEAN OPERATORS


Operators used in Boolean algebra are known as Boolean/logical operators. Basic logical
operators and their notations are shown below:
AND +C+
OR NOT
!
EXAMPLES
X.Y X+Y X
XAY XVY ~X

2.6.1 AND Operator


AND operator is a binary operator that operates on two variables and the operation performed
by AND operator is known as logical multiplication. The symbol used for logical multiplication
is dot () operator.
Consider the following values for two variables in a given Table 1. Now, when there is logical
multíplication using AND operator, the result will be as shown in Table 2.
Table 1 Table 2
A B A B OUTPUT A.B
0 0
0 1 1
1 0 0
1 1 1 1

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).

Data Representation and Boolean Logic 2.23


2.6.2 0R Operator
The OR operator is abinary operator that operates on two variables and the operation performed
by OR operator is known as logical addition. The symbol used for logical addition is plus
operator.
Consider the following values for two variables Aand Bas shown in Table 1. When there is logical
addition using OR operator, the result will be as shown in Table 2:
Table 1 Table 2

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.

2.7 TRUTH TABLE


A truth table is a representation of a Boolean function or expression containing all possible
combinations of input values and their result in a tabular format. If the result of a logical
expression or logical statement is always true or 1, it is known as Tautology. If the result is
always false or 0, it is known as Fallacy.
The number of rows in a truth table is calculated as 2" where n is the total number of Boolean
variables. Therefore, if there are two variables Aand B, then the possible input values will be
22 = 4 combinations.

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

Rules for writing Truth Table


1. First check the number of literals or variables in a Boolean expression.
2. Draw columns for each unique variable. For example, if there is aBoolean expression as A+B.C,
then there will be three columns, one for each variable.
3. Draw columns for each logical expression. In a Boolean expression A+B.C, there are two logical
operations, viz. AND and OR operations.
4. Draw rows which can be calculated as 2n where n is the total number of variables. In the
example given above, there are three variables A, B and C. Hence, total number of rows will
be 23 = 8.
5. Write 0's in the first half for the number of rows in the first column and in the second half,
for number of rows, write 1's.
6. Similarly, write 0's in the first half for the number of rows which have 0's in the first column
and 1's in the same number of rows. Repeat this pattern till O's and 1's have been written
for all 0's and 1's of the first column.
7. This pattern will continue till you reach the last column wìth the pattern 0's and 1's
alternatively.
8. Calculate the result for each logical operation by considering the values for input variables
written in each row.
Let us discuss some questions on creating truth table for Boolean expressions.

Data Representation and Boolean Logc 2.25


Q. Write a truth table for the Boolean expression: F=A.B'+C by writing each sten
Ans. Follow the given steps for writing the truth table:
1. In the given expression, there are three variables A, B and
C.
2. Draw three columns for each possible input variable combination and three columne c
each logical operations NOT, AND and OR and 2 = 8 rows such as:
A B B A.B' A.B'+C

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

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

CTM: Number of columns = Number of variables + Number of logical expressions


Nunber of rows = 2" wheren is the total number

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

> Precedence of Boolean Operators


1. NOT (First Precedence)
AND (Second Precedence)
3. OR (Third Precedence)
The NOT operator has the highest priority and OR has the lowest priority. For evaluating the
Boolean expression, the following rules should be followed:
> Rules for Evaluating Boolean Expression
1. Evaluate the Boolean expression from left to right.
2. Evaluate the expression in parentheses first.
3. Perform all NOT expressions.
4. Perform all AND expressions.
5. Perform all OR expressions.
Precedence of operators can also be illustrated with the help ofa truth table. Consider a Boolean
expression X.Y+Z

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.

2.8 LOGIC CIRCUIT


A logic circuit is the one which takes one or more inputs and generates an output. Logic Gates
use the binary operators AND, OR and NOT. There are three fundamental Logic Gates which are
as follows:
1. NOT Gate 2. AND Gate 3. OR Gate

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

NAND X Y X.Y (X.Y)'


0 1
X
1

1 0 1 Y

1 1 1

NOR X Y X+Y (X+Y)'


X
0 1 -X+Y
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.

Data Representation andBoolean Logic 2.29


Q. Draw a circuit diagram corresponding to the following Boolean expression:
F=A.B'+C:D
Ans. A
B

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

2.9 DE MORGAN'S LAW


A famous mathematician De Morgan has suggested two laws which are extremely useful in
Boolean Algebra. The rules of De Morgan's theorem are produced from the Boolean expressions
for OR, AND and NOT. The two laws have been discussed below.
The first law states that when two (or more) input variables are OR'ed and negated, they are
equivalent to the AND of the complements of the individual variables.
A+B =A.B
Let P=(A+B)
Therefore,
P+P'=1and P.P'=0 [Complementary law]
Substitute (A+B) for P and (A+B)' for P, we have:
(A+B) + (A+B)' =1 and (A+B).(A+B)'=0
But, (A+B)'=A.B'
Therefore,
(A+B)+(A'B)=1 and (A+B).(A.B)=0

Let us prove (A+B) +(A:B)=1


=(A+B)+(AB))
=(A+B+A).(A+B+B') [Distributive law]
= (A+A+B).(A+B+B') [Commutative law]
We know that A+A'=1 and B+B'=1 [Inverse law]
Therefore,
=(1+B).(A+1) [because, 1+A=1 and 1+B=lusing property of 1]
=1,1
=1

Hence proved.

Data Representation and Boolean Logic 2.31


Let us prove (A+B).(A.B')=0
= (A+B).(A.B) = (A.A.B) + (B.A.B) [Distributive law]
(A.A.B)) + (A.B.B) [Commutative law]
-(0.B') + (A.0) [A.A'=0 and B.B'=0Inverse law]
=0.0 [0.A'=0and 0.B'=0 property of 0]
=0

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

Logicgate implementation of the above theorem is:

A
B Bo A+ B

Fig. 2.7: First Law of De Morgan's Theorem

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

Let us prove the second part P.P'=0


=(A.B).(A+B')
=A.B.A' + A.B.B' [Distributive law]
=A.A.B + A.B.B' [Commutative law]
=0.B + A.0 [Inverse law A.A=0]
=0 + 0 [Property of 0,0+0=0]
=0

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

Logic gate implementation of the above theorem is:


A A.B
-(A.B)'
B

Fig. 2.8: Second Law of De Morgan's Theorem

It is equivalent to:

- +B

Data Representation and Boolean Logic 2.33

You might also like