37 Computer Science Unit-02
37 Computer Science Unit-02
Key concepts
Number systems
o Decimal, binary, octal,
hexadecimal Computer is a machine that can handle different
Number conversions types of data items. We feed data such as
Data representation numbers, characters, images, videos and sounds
o Representation of integers to a computer for processing. We know that
and floating point numbers computer is an electronic device functioning on
o Character representation: the basis of two electric states - ON and OFF.
ASCII, EBCDIC, ISCII, All electronic circuits have two states - open
UNICODE
and closed. The two-state operation is called
o Representation of audio,
image and video data
binary operation. Hence, the data given to
Binary arithmetic
computer should also be in binary form. In this
chapter we will discuss various methods for
o Addition, subtraction,
complements representing data such as numbers, characters,
Introduction to Boolean images, videos and sounds.
algebra
o Logic operators and logic
gates
Basic postulates
Basic theorems
Circuit designing for simple
Boolean expressions
Universal gates
en
constructing a number. A number system has a unique base, which depends upon the
number of symbols. The number of symbols used in a number system is called base
or radix of a number system.
Let us discuss some of the number systems.
2.1.1 Decimal number system
im
The decimal number system involves ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 to form
a number. Since there are ten symbols in this number system, its base is 10. Therefore,
the decimal number system is also known as base-10 number system.
Consider two decimal numbers 743 and 347
743 seven hundred + four tens+ three ones ( 7102 + 4101 + 3100)
c
347 three hundreds + four tens + seven ones ( 3102 + 4 101+ 7100)
Here, place value (weight) of 7 in first number 743 is 10 2 =100. But weight of 7 in
second number 347 is 100=1. The weight of a digit depends on its relative position.
e
Such a number system is known as positional number system. All positional number
systems have a base and the place value of a digit is some power of this base.
p
Place value of each decimal digit is power of 10 (100, 101, 102, ...). Consider a decimal
number 5876.
This number can be written in expanded form as
S
28
2. Data Representation and Boolean Algebra
Digit (MSD) and the digit with least weight is called Least Significant Digit (LSD). So
in the above number MSD is 5 and LSD is 6.
Left most digit of a number is MSD and right most digit of a number is LSD
For fractional numbers weights are negative powers of 10 (10-1, 10-2, 103, …) for the
digits to the right of decimal point. Consider another example 249.367
Weight 102 101 100 10-1 10-2 10-3
en
Decimal Number 2 4 9 3 6 7
MSD (.) LSD
= 2102 + 4 101 + 9100 + 310-1 + 610-2 + 710-3
= 2100 + 4 10 + 91 + 30.1 + 60.01 + 70.001
=
=
200 + 40 + 9 + 0.3 + 0.06 + 0.007
249.367
im
So far we have discussed a number system which uses 10 symbols. Now let us see the
construction of other number systems with different bases.
2.1.2 Binary number system
A number system which uses only two symbols 0 and 1 to form a number is called
c
binary number system. Bi means two. Base of this number system is 2. So it is also
called base-2 number system. We use the subscript 2 to indicate that the number is in
binary.
e
The binary number system is also a positional number system where place value of
each binary digit is power of 2. Consider an example (1101)2. This binary number can
be written in expanded form as shown below:
S
Weight 23 22 21 20
Binary Number 1 1 0 1
MSB LSB
= 123 + 1 22 + 021 + 120
= 18 + 14 + 02 + 11
= 8+4+0+1
= 13
The right most bit in a binary number is called Least significant Bit (LSB). The leftmost
bit in a binary number is called Most significant Bit (MSB).
29
The binary number 1101 is equivalent to the decimal number 13. The number 1101
also exists in the decimal number system. But it is interpreted as one thousand one
hundred and one. To avoid this confusion, base must be specified in all number systems
other than decimal number system. The general format is
(Number)base
This notation helps to differentiate numbers of different bases. So a binary number
en
must be represented with base 2 as (1101)2 and it is read as “one one zero one to the
base two”.
If no base is given in a number, it will be considered as decimal. In other words,
specifying the base is not compulsory in decimal number.
For fractional numbers, weights are negative powers of 2 (2-1, 2-2, 2-3, …) for the
im
digits to the right of the binary point. Consider an example (111.011)2
Weight 22 21 20 2-1 2-2 2-3
Binary Number 1 1 1 0 1 1
MSB (.) LSB
= 122 + 121 + 120 + 02-1 + 12-2 + 12-3
c
1 1 1
= 14 + 12 + 11 + 0 + 1 + 1
2 4 8
= 4 + 2 + 1 + 0 + 0.25 + 0.125
e
= 7.375
Importance of binary numbers in computers
p
We have seen that binary number system is based on two digits 1 and 0. The electric
state ON can be represented by 1 and the OFF state by 0 as in Figure 2.2. Because of
this, computer uses binary number system as the basic number system for data
representation.
S
1 0 1 0 1 1 0
30
2. Data Representation and Boolean Algebra
octal. Base of this number system is 8 and hence it is also called base-8 number system.
Consider an example (236)8. Weight of each digit is power of 8 (80, 81, 82, 83, ...). The
number (236)8 can be written in expanded form as
Weight 82 81 80
Octal Number 2 3 6
en
= 282 + 381 + 680
= 264 + 38 + 61
= 128 + 24 + 6
= 158
For fractional numbers weights are negative powers of 8, i.e. (8-1, 8-2, 8-3, …) for the
Octal Number
=
82
1
im
digits to the right of the octal point. Consider an example (172.4)8
Weight 81
7
80
2
182 + 781 + 280 + 48-1
8-1
4
1
c
= 64 + 56 + 2 + 4
8
= 122 + 0.5
= 122.5
e
to form a number is called hexadecimal number system. Base of this number system is
16 as there are sixteen symbols in this number system. Hence this number system is
also called base-16 number system.
S
In this system, the symbols A, B, C, D, E and F are used to represent the decimal
numbers 10, 11, 12, 13, 14 and 15 respectively. The hexadecimal digit and their equivalent
decimal numbers are shown below.
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Consider a hexadecimal number (12AF)16. Weights of each digit is power of 16 (160,
161, 162, ...).
31
This number can be written in expanded form as shown below:
Weight 163 162 161 160
Hexadecimal Number 1 2 A F
= 1163 + 2162 + 10161 + 15160
= 14096 + 2256 + 1016 + 151
en
= 4096 + 512 + 160 + 15
= 4783
For fractional numbers, weights are some negative power of 16 (16-1, 16-2, 16-3, ...) for
the digits to the right of the hexadecimal point. Consider an example (2D.4)16
Weight 161 160 16-1
im
Hexadecimal 2 D 4
1
= 2161 + 13160 + 4
16
= 32 + 13 + 0.25
= 45.25
c
Table 2.1 shows the base and symbols used in different number systems:
Binary 2 0, 1
Octal 8 0, 1, 2, 3, 4, 5, 6, 7
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
p
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Table 2.1 : Number systems with base and symbols
S
32
2. Data Representation and Boolean Algebra
Check yourself
1. Number of symbols used in a number system is called ____.
2. Pick invalid numbers from the following
i) (10101)8 ii) (123)4 iii) (768)8 iv) (ABC)16
3. Define the term ‘bit’.
en
4. Find MSD in the decimal number 7854.25.
5. The base of hexadecimal number system is _______.
im
numbers of one base to the equivalent numbers in other bases. There are different
types of number conversions like decimal to binary, binary to decimal, decimal to
octal etc. This section discusses how to convert one number system to another.
2.2.1 Decimal to binary conversion
The method of converting decimal number to binary number is by repeated division.
In this method the decimal number is successively divided by 2 and the remainders are
c
recorded. The binary equivalent is obtained by grouping all the remainders, with the
last remainder being the Most Significant Bit (MSB) and first remainder being the
Least Significant Bit (LSB). In all these cases the remainders will be either 0 or 1 (binary
digit).
e
Examples:
Find binary equivalent of decimal Find binary equivalent of (80)10.
p
2 20 0
2 12 1 LSB
2 10 0
2 6 0
2 5 0
2 3 0
2 2 1
2 1 1
2 1 0
0 1 MSB
0 1 MSB
(25)10 = (11001)2 (80)10 = (1010000)2
33
Hint: Binary equivalent of an odd decimal number ends with 1 and binary of even
decimal number ends with zero.
Converting decimal fraction to binary
To convert a fractional decimal number to binary, we use the method of repeated
multiplication by 2. At first the decimal fraction is multiplied by 2. The integer part of
the answer will be the MSB of binary fraction. Again the fractional part of the answer
en
is multiplied by 2 to obtain the next significant bit of binary fraction. The procedure is
continued till the fractional part of product is zero or a desired precision is obtained.
Example: Convert 0.75 to binary.
0.75 2 = 1.50
1 .50 2 = 1.00
1 .00
1 .25 2 = 0.50
c
0 .50 2 = 1.00
1 .00
e
(0.625)10 = (0.101)2
2 3 1 0 .50 2 = 1.00
2 1 1 1 .00
0 1
(15.25)10 = (1111.01)2
34
2. Data Representation and Boolean Algebra
are recorded. The octal equivalent is obtained by grouping all the remainders, with the
last remainder being the MSD and first remainder being the LSD. Remainders will be
0, 1, 2, 3, 4, 5, 6 or 7.
Example: Find octal equivalent of decimal number 125.
8 125 Remainders
8 15 5 LSD
en
8 1 7
0 1 MSD (125)10= (175)8
0
6
Remainders
0
2
6
im (400)10=(620)8
c
2.2.3 Decimal to hexadecimal conversion
The method of converting decimal number to hexadecimal number is also by repeated
division . In this method, the number is successively divided by 16 and the remainders
e
are recorded. The hexadecimal equivalent is obtained by grouping all the remainders,
with the last remainder being the Most Significant Digit (MSD) and first remainder
being the Least Significant Digit(LSD). Remainders will be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,
p
B, C, D, E or F.
Example: Find hexadecimal equivalent of decimal number 155.
16 155 Remainders
S
16 9 11 (B) LSD
0 9 MSD (155)10= (9B)16
Example: Find hexadecimal equivalent of 380.
16 380 Remainders
16 23 12 (C)
16 1 7 (380)10= (17C)16
0 1
35
2.2.4 Binary to decimal conversion
A binary number can be converted into its decimal equivalent by summing up the
product of each bit and its weight. Weights are some power of 2 (20, 21, 22, 23, ...).
Example: Convert (11011)2 to decimal.
(11011)2 = 124 + 123 + 022 + 121 + 120 Weight 24 23 22 21 20
= 16 + 8 + 2 + 1 Bit 1 1 0 1 1
en
= 27 (11011) 2 =(27)10
Example: Convert (1100010)2 to decimal.
Weight 26 25 24 23 22 21 20
im
Bit 1 1 0 0 0 1 0
(1100010)2 = 12 + 12 + 024 + 023 + 022 + 121 + 020
6
5
= 64 + 32 + 2
= 98 (1100010)2=(98)10
the product of each bit and its weight. Weights of binary fractions are negative powers
of 2 (2-1, 2-2, 2-3, ...) for the digits after the binary point.
Example: Convert (0.101)2 to decimal.
S
36
2. Data Representation and Boolean Algebra
(1010.11)2 = (10.75)10
Table 2.3 shows some negative powers of 2.
en
2-1 2-2 2-3 2-4 2-5
0.5 0.25 0.125 0.0625 0.03125
Table 2.3 : Negative powers of 2
2.2.5 Octal to decimal conversion
83, ...).
Example: Convert (157)8 to decimal.
(157)8 = 18 + 58 + 78
2 1 0
im
An octal number can be converted into its decimal equivalent by summing up the
product of each octal digit and its weight. Weights are some powers of 8 (80, 81, 82,
Weight 82 81 80
Octal digit 1 5 7
= 64 + 40 +7
c
= 111 (157)8 = (111)10
Example: Convert (1005)8 to decimal.
e
37
Example: Convert (2D5)16 to decimal.
(2D5)16 = 2162+13161+5160 Weight 162 161 160
= 512+208+5 Hexadecimal digit 2 D 5
= 725 D = 13
(2D5)16 = (725)10
2.2.7 Octal to binary conversion
en
An octal number can be converted into binary by converting each octal digit to its 3
bit binary equivalent. Eight possible octal digits and their binary equivalents are listed
in Table 2.4.
Octal Digit 0 1 2 3 4 5 6 7
im
Binary Equivalent 000 001 010 011 100 101 110 111
Table 2.4 : Binary equivalent of octal digit
7 2 0 1
111 010 000 001
S
(7201)8 = (111010000001)2
38
2. Data Representation and Boolean Algebra
A B Hexa Binary
decimal equivalent
en
4-bit binary equivalents of each hexadecimal digit are 4 0100
2 F 1 5 5 0101
6 0110
0010 1111 0001 0101 7 0111
8 1000
im
(2F15)16 = (10111100010101)2
9 1001
2.2.9 Binary to octal conversion
A 1010
A binary number can be converted into its octal equivalent
B 1011
by grouping binary digits to group of 3 bits and then each
group is converted to its octal equivalent. Start grouping C 1100
from right to left. D 1101
c
Example: Convert (101100111)2 to octal. E 1110
We can group above binary number 101100111 from right F 1111
as shown below.
e
Table 2.5 :
Binary equivalent of
101 100 111 hexadecimal digits
p
5 4 7
(101100111)2 = (547)8
We can group above binary number 10011000011 from right as shown below.
010 011 000 011
After grouping, if the
left most group has no 2 3 0 3
3 bits, then add
leading zeros to form (10011000011)2 = (2303)8
3 bit binary.
39
2.2.10 Binary to hexadecimal conversion
A binary number can be converted into its hexadecimal equivalent by grouping binary
digits to group of 4 bits and then each group is converted to its hexadecimal equivalent.
Start grouping from right to left.
Example: Convert (101100111010)2 to hexadecimal.
We can group the given binary number 101100111010 from right as shown below:
en
1011 0011 1010
B 3 A
(101100111010)2 = (B3A)16
im
Example: Convert (110111100001100)2 to hexadecimal.
We can group the given binary number 110111100001100 from right as shown below:
0110 1111 0000 1100
After grouping, if the
left most group has no
4 bits, then add 6 F 0 C
leading zeros to form (110111100001100)2 = (6F0C)16
c
4 bit binary.
2.2.11 Octal to hexadecimal conversion
Conversion of an octal number to hexadecimal number is a two step process. Octal
e
number is first converted into binary. This binary equivalent is then converted into
hexadecimal.
p
100 101 111
= (100101111)2
Then convert (100101111)2 into hexadecimal as follows:
(100101111)2 = 0001 0010 1111
= 1 2 F
= (12F)16 (457)8 = (12F)16
40
2. Data Representation and Boolean Algebra
en
(A2D)16 = A 2 D
1010 0010 1101
= (101000101101)2
Then convert (101000101101)2 into octal as follows:
(101000101101)2 = 101 000 101 101
5
= (5055)8
(A2D)16 = (5055)8
0
im
5
Conversion Procedure
c
Decimal to Binary Repeated division by 2 and grouping the remainders
Decimal to Octal Repeated division by 8 and grouping the remainders
e
Octal to Binary Converting each octal digit to its 3 bit binary equivalent
Hexadecimal to Binary Converting each hexadecimal digit to its 4 bit binary
equivalent
Binary to Octal Grouping binary digits to group of 3 bits from right to
left
Binary to Hexadecimal Grouping binary digits to group of 4 bits from right to
left
Octal to Hexadecimal Convert octal to binary and then binary to hexadecimal
Hexadecimal to Octal Convert hexadecimal to binary and then binary to octal
Table 2.6 : Procedure for number conversions
41
Check yourself
1 Convert the decimal number 31 to binary.
2 Find decimal equivalent of (10001)2
3 If (x)8 = (101011)2, then find x.
4 Fill in the blanks:
en
a) ( _______ )2 = (AB)16
b) (___D__)16 = (1010____1000)2
c) 0.2510 = ( ______ )2
5 Find the largest number in the list
(i) (1001)2 (ii) (A)16 (iii) (10)8 (iv) (11)10
Numbers can be classified into integer numbers and floating point numbers. Integers
are whole numbers or numbers without any fractional part. A floating point number
or a real number is a number with fractional part. These two numbers are treated
p
They are
i) Sign and magnitude representation
ii) 1’s complement representation
iii) 2’s complement representation
The following data representation methods are based on 8 bit word length.
A word is basically a fixed-sized group of bits that are handled as a unit by a processor.
Number of bits in a word is called word length. The word length is the choice of
computer designer and some popular word lengths are 8, 16, 32 and 64.
42
2. Data Representation and Boolean Algebra
en
Sign Magnitude
Number is positive, so first bit (MSB) is 0.
7 bit binary equivalent of 23 = (0010111)2
0 0 0 1 0 1 1 1
So + 23 can be represented as (00010111)2
im
Number is negative, so first bit(MSB) is 1
7 bit binary equivalent of 105 = (1101001)2
So -105 can be represented as (11101001)2
Sign
1 1 1
Magnitude
0 1 0
Note: In this method an 8 bit word can represent 28-1 =255 numbers (i.e. -127 to
0 1
+127). Similarly, a 16 bit word can represent 216-1 = 65535 numbers (i.e. -32767 to
c
+32767). So, an n-bit word can represent 2n-1 numbers i.e., –(2n-1-1) to +(2n-1-1). The
integer 0 can be represented in two ways: +0 = 00000000 and –0 = 10000000.
ii. 1’s complement representation
e
In this method, first find binary equivalent of absolute value of integer. If number of
digits in binary equivalent is less than 8, provide zero(s) at the left to make it 8-bit
form. 1’s complement of a binary number is obtained by replacing every 0 with 1 and
p
every 1 with 0. Some binary numbers and the corresponding 1's compliments are
given below:
Binary Number 1’s Complement
S
11001 00110
10101 01010
If the number is negative it is represented as 1’s complement of 8-bit form binary. If
the number is positive, the 8-bit form binary equivalent itself is the 1's complement
representation.
Example: Represent -119 in 1’s complement form.
Binary of 119 in 8-bit form = (01110111)2
-119 in 1’s complement form = (10001000)2
43
Example: Represent +119 in 1’s complement form.
Binary of 119 in 8-bit form = (01110111)2
+119 in 1’s complement form = (01110111)2
(No need to find 1’s complement, since the number is positive)
Note: In this representation if first bit (MSB) is 0 then number is positive and if MSB
is 1 then number is negative. So 8 bit word can represent integers from -127 (represented
en
as 10000000) to +127 (represented as 01111111). Here also integer 0 can be
represented in two ways: +0 = 00000000 and –0 = 11111111. An n-bit word can
represent 2n-1 numbers i.e. -(2n-1-1) to +(2n-1-1).
iii. 2’s complement representation
im
In this method, first find binary equivalent of absolute value of integer and write it in
8-bit form. If the number is negative, it is represented as 2’s complement of 8-bit
form binary. If the number is positive, 8-bit form binary itself is the representation.
2’s complement of a binary number is calculated by adding 1 to its 1’s complement.
For example, let us find the 2’s complement of (10101)2.
1’s complement of (10101)2 = (01010)2
c
So 2’s complement of (10101)2 = 01010 +
1
= (01011)2
e
1
= (11011010)2
Example: Represent +38 in 2’s complement form.
S
44
2. Data Representation and Boolean Algebra
en
-6 1110 1001 1010
-5 1101 1010 1011
-4 1100 1011 1100
-3 1011 1100 1101
-2 1010 1101 1110
-1
0
1
2
1001
1000 or 0000
0001
0010
im 1110
0000 or 1111
0001
0010
1111
0000
0001
0010
3 0011 0011 0011
c
4 0100 0100 0100
5 0101 0101 0101
6 0110 0110 0110
e
is, if the MSB is 1, the number is negative and if it is 0, the number is positive.
The table also shows that only 2's complement method can represent the
maximum numbers for a given number of bits. This fact reveals that, a number
S
below -7 and above +7 cannot be represented using 4-bits in sign & magnitude
form and 1's complement form. So we go for 8-bit representation. Similarly in
2's complement method, if we want to handle numbers outside the range -8 to
+7, eight bits are required.
In 8-bits implementation, the numbers from -128 to +127 can be represented
in 2's complement method. The range will be -127 to +127 for the other two
methods. For the numbers outside this range, we use 16 bits and so on for all
the representations.
45
Features Sign & Magnitude 1’s Complement 2’s Complement Remarks
en
representation
Representation Binary equivalent Binary equivalent Binary equivalent All three forms
of positive of integer in 8 bit of integer in 8 bit of integer in 8 bit are same.
integers form form form
Representation Sign bit 1 and Find 1's Find 2's For all negative
im
of negative magnitude is complement of complement of 8 numbers MSB is
integers represented in 7 8 bit form binary bit form binary 1
bit binary form
Table 2.7 : Comparison for representation of integers in 8-bit word length
b. Representation of floating point numbers
A floating point number / real number consists of an integer part and a fractional
c
part. A real number can be written in a special notation called the floating point
notation. Any number in this notation contains two parts, mantissa and exponent.
For example, 25.45 can be written as 0.2545×102, where 0.2545 is the mantissa and the
e
power 2 is the exponent. (In normalised floating point notation mantissa is between
0.1 and 1). Similarly -0.0035 can be written as -0.35x10-2, where -0.35 is mantissa and
-2 is exponent.
p
Let us see how a real number is represented in 32 bit word length computer. Here 24
bits are used for storing mantissa ( among these the first bit is for sign) and 8 bits are
used for storing exponent (first bit for sign) as in Figure 2.3. Assume that decimal
S
point is to the right of the sign bit of mantissa. No separate space is reserved for
storing decimal point.
Sign 32 bits Sign
46
2. Data Representation and Boolean Algebra
Consider the real number 25.45 mentioned earlier, that can be written as 0.2545102,
where 0.2545 is the mantissa and 2 is the exponent. These numbers are converted into
binary and stored in respective locations. Various standards are followed for
representing mantissa and exponent. When word length changes, bits used for storing
mantissa and exponents will change accordingly.
In real numbers, binary point keeps track of mantissa part and
exponent part. Since the value of mantissa and exponent varies from
en
number to number the binary point is not fixed. In other words it
floats and hence such a representation is called floating point
representation.
im
We have discussed methods for representing numbers in computer memory. Similarly
there are different methods to represent characters. Some of them are discussed below.
a. ASCII
The code called ASCII (pronounced “AS-key”), which stands for American Standard
Code for Information Interchange, uses 7 bits to represent each character in computer
memory. The ASCII representation has been adopted as a standard by the U.S.
c
government and is widely accepted. A unique integer number is assigned to each
character. This number called ASCII code of that character is converted into binary
e
for storing in memory. For example, ASCII code of A is 65, its binary equivalent in 7-
bit is 1000001. Since there are exactly 128 unique combinations of 7 bits, this 7-bit
code can represent only128 characters.
p
Another version is ASCII-8, also called extended ASCII, which uses 8 bits for each
character, can represent 256 different characters. For example, the letter A is represented
by 01000001, B by 01000010 and so on. ASCII code is enough to represent all of the
S
47
c. ISCII
ISCII stands for Indian Standard Code for Information Interchange or Indian Script
Code for Information Interchange. It is an encoding scheme for representing various
writing systems of India. ISCII uses 8-bits for data representation. It was evolved by
a standardisation committee under the Department of Electronics during 1986-88,
and adopted by the Bureau of Indian Standards (BIS). Nowadays ISCII has been
replaced by Unicode.
en
d. Unicode
Using 8-bit ASCII we can represent only 256 characters. This cannot represent all
characters of written languages of the world and other symbols. Unicode is developed
to resolve this problem. It aims to provide a standard character encoding scheme,
which is universal and efficient. It provides a unique number for every character, no
im
matter what the language and platform be.
Unicode originally used 16 bits which can represent up to 65,536 characters. It is
maintained by a non-profit organisation called the Unicode Consortium. The
Consortium first published the version 1.0.0 in 1991 and continues to develop standards
based on that original work. Nowadays Unicode uses more than 16 bits and hence it
can represent more characters. Unicode can represent characters in almost all written
c
languages of the world.
2.3.3 Representation of audio, image and video
In the previous sections we have discussed different data representation techniques
e
and standards used for the computer representation of numbers and characters. While
we attempt to solve real life problems with the aid of a digital computer, in most cases
we may have to represent and process data other than numbers and characters. This
p
may include audio data, images and videos. We can see that like numbers and characters,
the audio, image and video data also carry information. In this section we will see
different file formats for storing sound, image and video.
S
48
2. Data Representation and Boolean Algebra
The data can be stored uncompressed or compressed to reduce the file size. Normally,
the image data is stored in compressed form. Let us understand what compression is.
Take a simple example of a pure black image of size 400×400 pixels. We can repeat
the information black, black, …, black in all 16,0000 (400×400) pixels. This is the
uncompressed form, while in the compressed form black is stored only once and
information to repeat it 1,60,000 times is also stored. Numerous such techniques are
used to achieve compression. Depending on the application, images are stored in
en
various file formats such as bitmap file format (BMP), Tagged Image File Format
(TIFF), Graphics Interchange Format (GIF), Portable (Public) Network Graphic
(PNG).
What we said about the header file information and compression is also applicable for
audio and video files. Digital audio data can be stored in different file formats like
im
WAV, MP3, MIDI, AIFF, etc. An audio file describes a format, sometimes referred to
as the ‘container format’, for storing digital audio data. For example WAV file format
typically contains uncompressed sound and MP3 files typically contain compressed
audio data. The synthesised music data is stored in MIDI(Musical Instrument Digital
Interface) files. Similarly video is also stored in different files such as AVI (Audio Video
Interleave) - a file format designed to store both audio and video data in a standard
c
package that allows synchronous audio with video playback, MP3, JPEG-2, WMV,
etc.
e
Check yourself
1. Which is the MSB of representation of -80 in the sign and
magnitude method?
p
5. Define Unicode.
6. List any two image file formats.
49
2.4.1 Binary addition
The rules for adding two bits are as follows:
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
en
1 1 0 1
Note that a carry bit 1 is created only when two ones are added. If three ones are
added (i.e. 1+1+1), then the sum bit is 1 with a carry bit 1.
Example: Find sum of binary numbers Example: Find sum of binary numbers
1011 and 1001. 110111 and 10011.
im
1011+ 110111 +
1001 100110
10 1 0 0 1011101
2.4.2 Binary subtraction
The rules for subtracting a binary digit from another digit are as follows.
c
A B Difference Borrow
0 0 0 0
0 1 1 1
e
1 0 1 0
1 1 0 0
p
Note that when 1 is subtracted from 0 the difference is 1, but 1 is borrowed from
immediate left bit of first number. The above rules can be used only when a small
binary number is subtracted from a large binary number.
S
50
2. Data Representation and Boolean Algebra
subtract through addition. For that we use the concept of complements. There are
two methods of subtraction using complements.
Subtraction using 1’s complement
The steps for subtracting a smaller binary number from a larger binary number are:
Step 1: Add 0s to the left of smaller number, if necessary, to make two numbers
with same number of bits.
en
Step 2: Find 1’s complement of subtrahend (Number to be subtracted, here small
number )
Step 3: Add the complement with minuend (Number from which subtracting, here
larger number)
Step 4: Add the carry 1 to the sum to get the answer.
MSB
im
Example: Subtract 1002 from 10102 using 1’s complement.
At first find 1’s complement of 0100 and it is 1011
1010 +
1011
1 0101
c
0101 + MSB is removed and
1 added with the result
Step 1: Add 0s to the left of smaller number, if necessary, to make the two numbers
have the same number of bits.
S
51
Example: Subtract (100)2 from (1010)2 using 2’s complement.
2’s complement of 0100 1100
Add it with larger number, i.e. 1010 +
Ignore the carry to 1100
get the result 1 0110
The result is 110
en
2.5 Introduction to Boolean algebra
In many situations in our life we face questions that require
‘Yes’ or ‘No’ answers. Similarly much of our thinking process
involves answering questions with ‘Yes’ or ‘No’. The way of
finding truth by answering such two-valued questions is known
im
as human reasoning or logical reasoning. These values can be
expressed as ‘True’ or ‘False’ and numerically 1 or 0. These
values are known as binary values or Boolean values. Boolean
algebra is the algebra of logic which is a part of mathematical
algebra that deals with the operations on variables that represent
the values 1 and 0. The name Boolean algebra is given to honour Fig. 2.4 : George
the British mathematician George Boole, as he was the person Boole (1815 - 1864)
who established the link between logic and mathematics. His
c
revolutionary paper ‘An Investigation of the laws of thought’ led to the development
of Boolean algebra.
e
are called binary decisions and the results are called binary values. The 3rd statement is
TRUE and 4th statement is FALSE. But 5th and 6th sentences cannot be answered like
the cases above. The sentences which can be determined to be TRUE or FALSE are
called logical statements or truth functions and the results TRUE or FALSE are
called binary values or logical constants. The logical constants are represented by 1
and 0, where 1 stands for TRUE and 0 for FALSE. The variables which can store
(hold) logical constants 1 and 0 are called logical variables or Boolean variables.
52
2. Data Representation and Boolean Algebra
en
follows:
OR Logical Addition
AND Logical Multiplication
NOT Logical Negation
The first two operators require two operands and the third requires only one operand.
Here the operands are always Boolean variable or constants and the result will always
be either True (1) or False (0).
im
Computers perform these operations with some electronic circuits, called logic circuits.
A logic circuit is made up of individual units called gates, where a gate represents a
Boolean operation. A Logic gate is a physical device that can perform logical
operations on one or more logical inputs and produce a single logical output. Logic
gates are primarily implemented using diodes or transistors acting as electronic switches.
c
There are three basic logic gates and they represent the three basic Boolean operations.
These gates are OR, AND and NOT.
a. The OR operator and OR gate
e
Let us consider a real life situation. When do you use an umbrella? When it rains, isn’t
it? And of course, if it is too sunny. We can combine these two situations using a
compound statement like “If it is raining or if it is sunny, we use an umbrella”. Note
p
53
Truth Table is a table that shows Boolean A B A+B
operations and their results. It lists all possible 0 0 0
inputs for the given operation and their 0 1 1
corresponding output. Usually these
1 0 1
operations consist of operand variables and
1 1 1
operators. The operands and the operators
Table 2.9 : Truth table of OR operation
together are called Boolean expression. Truth
en
Table represents all possible values of the operands and the corresponding results
(values) of the operation. A Boolean expression with m operands (variables) and n
operators require 2m rows and m+n columns.
While designing logic circuits, the logic gate used to
implement logical OR operation is called logical OR gate.
im
Figure 2.5 shows the OR gate symbol in Boolean algebra.
The working of this gate can be illustrated with an electronic Fig. 2.5 : Logical OR gate
circuit. Figure 2.6 illustrates the schematic circuit of parallel
switches which shows the idea of an OR gate. Here A and B are two switches and Y is
a bulb. Each switch and the bulb can take either close (ON) or open (OFF) state. Now
let us relate the operation of the above circuit with the functioning of OR gate. Assume
c
that OFF represents the logical LOW state (say 0) and ON represents the logical HIGH
(say 1) state. If we consider the state of switches A and B as input to the OR gate and
state of bulb as output of OR gate, then the truth table shown in Table 2.9 will describe
e
the operation of an OR gate. Thus the Boolean expression for OR gate can be written
as: Y = A + B
p
Y
S
Fig. 2.6 : Circuit with two switches and a bulb for parallel connection
An OR gate can take more than two inputs. Let us see what will be the truth table,
Boolean expression and logical symbol for the three input OR gate.
54
2. Data Representation and Boolean Algebra
en
if all inputs are 0. 1 0 1 1
1 1 0 1
1 1 1 1
Table 2.10 : Truth table for OR gate with 3
inputs
Fig 2.7 : OR gate
with three inputs
b. The AND operator and AND gate
We will discuss another situation to
understand the concept of AND Boolean
operation. Suppose you are away from home
im Hotel
No
No
Yes
Money
No
Yes
No
Take Food
No
No
No
and it is lunch time. You can have your food Yes Yes Yes
c
only if two conditions are satisfied – (i) there Table 2.11 : Logical AND operation
should be a hotel and (ii) you should have
enough money. Here also, we can make a compound A B A.B
e
1 0 0
of getting food and it very much resembles the 1 1 1
Boolean AND operation. Table 2.12 : Truth table of AND
The AND operator performs logical multiplication operation
S
While designing logic circuits, the logic gate used to implement logical AND operation
is called logical AND gate. Figure 2.8 shows the AND gate symbol in Boolean algebra.
55
The working of this gate can be
illustrated with an electronic circuit
shown in Figure 2.9. This schematic
Y
circuit has two serial switches which
illustrates the idea of an AND gate.
Here A and B are two switches and Y
is a bulb. Each switch and the bulb
en
can take either close (ON) or open Fig. 2.9 : Circuit with two switches and a bulb for
(OFF) state. Now let us relate the serial connection
operation of the above circuit with
the functioning of AND gate. Assume that
OFF represents the logical LOW state (say 0) A B C A.B.C
and ON represents the logical HIGH state (say 0 0 0 0
im
1). If we consider the state of switches A and 0 0 1 0
B as input to the AND gate and state of bulb 0 1 0 0
as output of AND gate, then the Boolean
0 1 1 0
expression for AND gate can be written as:
Y=A.B 1 0 0 0
1 0 1 0
An AND gate can take more than two inputs.
1 1 0 0
c
Let us see what will be the truth table, Boolean
expression and logical symbol for three input 1 1 1 1
AND gate. The truth table and the gate symbol Table 2.13 : Truth table for AND gate with 3
e
inputs
shows that the Boolean expression for the
AND gate with three inputs is Y = A . B . C
Figure 2.10 shows the representation of AND
p
56
2. Data Representation and Boolean Algebra
en
to implement NOT operation is NOT gate. Figure 2.11
shows the NOT gate symbol.
Fig. 2.11 : NOT gate
A NOT gate is also called inverter. It has only one input
and one output. The input is always changed into its opposite state. If input is 0 , the
NOT gate will give its complement or opposite which is 1. If the input is 1, then the
NOT gate will complement it to 0.
Check yourself
1.
2.
3.
im
Define the term Boolean variable.
A logic circuit is made up of individual units called _______.
Name the logical operator/gate which gives high output if and only
if all the inputs are high.
c
4. Define the term truth table.
5. An AND operation performs logical ________ and an OR
operation performs logical _______.
e
to build solid framework for scientific principles. On the other hand, there are some
theorems in Boolean algebra which can be proved based on these postulates and laws.
Postulate 1: Principles of 0 and 1
If A 0, then A = 1 and if A 1, then A=0
Postulate 2: OR Operation (Logical Addition)
0+0=0 0+1=1 1+0=1 1+1=1
Postulate 3: AND Operation (Logical Multiplication)
0.0=0 0.1=0 1.0=0 1.1=1
57
Postulate 4: NOT Operation (Logical Negation or Compliment Rule)
0 =1 1=0
Principle of Duality
When Boolean variables and/or values are combined with Boolean operators, Boolean
expressions are formed. X + Y and A + 1 are examples of Boolean expressions. The
postulates 2, 3 and 4 are all Boolean statements. Consider the statements in postulate
en
2. If we change the value 0 by 1 and 1 by 0, and the operator OR (+) by AND ( . ), we
will get the statements in postulate 3. Similarly, if we change the value 0 by 1 and 1 by
0, and the operator AND ( . ) by OR (+) in statements of postulate 3, we will get the
statements of postulate 2. This concept is known as principle of duality.
The principle of duality states that for a Boolean statement, there exists its dual form,
im
which can be derived by
(i) changing each OR sign ( + ) to AND sign ( . )
(ii) changing each AND sign ( . ) to OR sign ( + )
(iii) replacing each 0 by 1 and each 1 by 0
2.7 Basic theorems of Boolean algebra
c
There are some standard and accepted rules in every theory. The set of rules are known
as axioms of the theory. A conclusion can be derived from a set of presumptions by
using these axioms or postulates. This conclusion is called law or theorem. Theorems
e
58
2. Data Representation and Boolean Algebra
0 X 0+X 1 X 1+X
0 0 0 1 0 1
0 1 1 1 1 1
Table 2.16 (a) : Additive Identity law Table 2.16 (b) : Additive Identity law
Table 2.16 (a) shows that columns 2 and 3 are the same and it is proved that 0 + X =
en
X. Similarly, columns 1 and 3 of table 12.16 (b) are the same and hence the statement
1+X=1 is true.
0 X 0.X 1 X 1.X
0 0 0 1 0 0
0 1 0 1 1 1
im
Table 2.17(a) : Multiplicative Identity law Table 2.17(b) : Multiplicative Identity law
Table 2.17 (a) shows that columns 1 and 3 are the same and it is proved that 0 . X = 0.
Similarly, columns 2 and 3 of Table 2.17 (b) are the same and hence the statement
1. X=X is true.
2.7.2 Idempotent law
c
The idempotent law states that: (i) X + X = X
and (ii) X . X = X
e
(Postulate 2) and 0 . 0 = 0
1 1 1 1 1 1
(Postulate 3). Similarly the
statements will be true Table 2.18 (a) : Idempotent law Table 2.18 (b) : Idempotent law
when the value of X is 1. Truth Tables 2.18 (a) and 2.18 (b) shows the proof of these
S
laws. Also note that the statements are dual to each other.
2.7.3 Involution law
This law states that: X = X
Let X = 0, then X = 1 (Postulate 4); and if we take its
X X
compliment, X = 1= 0, which is same as X. The X
0 1 0
statement will also be true, when the value of X is 1.
1 0 1
Columns 1 and 3 of Table 2.19 show that X = X. Table 2.19 : Involution law
59
2.7.4 Complimentary law
The complimentary law states that: (i) X + X = 1
and (ii) X . X = 0
If the value of X is 0, then X becomes 1. Hence, X + X becomes 0 + 1, which results
into 1 (Postulate 2). Similarly when X is 1, X will be 0. The truth tables 2.20 (a) and
2.20 (b) show the proof of these laws taking all the possibilities. Also note that the
en
statements are dual to each other.
X X X+ X X X X. X
0 1 1 0 1 0
1 0 1 1 0 0
im
Table 2.20 (a) : Complimentary Table 2.20 (b) : Complimentary
law law
2.7.5 Commutative law
Commutative law allows to change the position of variables in OR and AND
operations. If X and Y are two variables, the law states that:
(i) X + Y = Y + X
c
and (ii) X . Y = Y . X
The truth table shown in Tables 2.21 (a) and 2.21 (b) prove these statements.
e
1 0 1 1 1 0 0 0
1 1 1 1 1 1 1 1
S
Table 2.21 (a) : Commutative law Table 2.21 (b) : Commutative law
The law ensures that order of the operands for OR and AND operations does not
affect the output in each case.
2.7.6 Associative law
In the case of three operands for OR and AND operations, associative law allows
grouping of operands differently. If X, Y and Z are three variables, the law states that:
(i) X + ( Y + Z ) = ( X + Y ) + Z
and (.(Y.Z)=(X.Y).Z
i i ) X
60
2. Data Representation and Boolean Algebra
The truth tables shown in Tables 2.22(a) and 2.22(b) prove these statements.
X Y Z X+Y Y+X X+(Y + Z) (X+Y)+Z
0 0 0 0 0 0 0
0 0 1 0 1 1 1
0 1 0 1 1 1 1
en
0 1 1 1 1 1 1
1 0 0 1 0 1 1
1 0 1 1 1 1 1
1 1 0 1 1 1 1
1 1 1 1 1 1 1
Y Z X.Y
im
Table 2.22(a) : Associative law 1
In Table 2.22(a), columns 6 and 7 show that X + ( Y + Z ) = ( X + Y ) + Z. Columns 6
and 7 of Table 2.22(b) show the validity of the experience X . ( Y . Z ) = ( X . Y ) . Z
X Y.Z X . (Y . Z) (X . Y) . Z
0 0 0 0 0 0 0
c
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 1 1 0 1 0 0
e
1 0 0 0 0 0 0
1 0 1 0 0 0 0
1 1 0 1 0 0 0
p
1 1 1 1 1 1 1
Table 2.22(b) : Associative law 2
S
Associative law ensures that the order and combination of variables in OR (logical
addition) or AND (logical multiplication) operations do not affect the final output.
2.7.7 Distributive law
Distributive law states that Boolean expression can be expanded by multiplying terms
as in ordinary algebra. It also supports expansion of addition operation over
multiplication. If X, Y and Z are variables, the law states that:
(i) X . ( Y + Z ) = X . Y + X . Z
and (ii) X + Y . Z = ( X + Y ) . ( X + Z )
61
The following truth tables prove these statements:
en
0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1
im
Table 2.23(a) : Distribution of Multiplication over Addition
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
p
1 1 1 1 1 1 1 1
Table 2.23(b) : Distribution of Addition over Multiplication
We are familiar with the first statement in ordinary algebra. To remember the second
statement of this law, find the dual form of the first.
2.7.8 Absorption law
Absorption law is a kind of distributive law in which two variables are used and the
result will be one of them. If X and Y are variables, the absorption law states that:
(i) X + ( X . Y ) = X
and (ii) X . ( X + Y ) = X
62
2. Data Representation and Boolean Algebra
The truth tables shown Tables 2.24(a) and 2.24(b) prove the validity of the statements
of absorption law.
X Y X.Y X+(X.Y) X Y X+Y X.(X+Y)
0 0 0 0 0 0 0 0
0 1 0 0 0 1 1 0
1 0 0 1 1 0 1 1
en
1 1 1 1 1 1 1 1
Table 2.24 (a) : Absorption law Table 2.24 (b) : Absorption law
Columns 1 and 4 of Table 2.24(a) and columns 1 and 4 of Table 2.24(b) show that the
laws are true.
im
Table 2.25 depicts all the Boolean laws we have discussed so far.
No. Boolean Law Statement 1 Statement 2
1 Additive Identity 0+X=X 1+X=1
2 Multiplicative Identity 0 . X = 0 1.X=X
3 Idempotent Law X+X=X X.X=X
c
4 Involution Law X =X
5 Complimentary Law X+ X =1 X. X =0
6 Commutative Law X+Y=Y+ X X.Y=Y.X
e
proved by applying some other laws. This method of proof is called algebraic proof.
Let us see some of them.
i. To prove that X . ( X + Y ) = X – Absorption law
LHS =X.(X+Y)
=X.X+X.Y (Distribution of multiplication over addition)
=X+X.Y (Idempotent law)
=X.(1+Y) (Distribution of multiplication over addition)
63
=X.1 (Additive identity)
=X (Multiplicative identity)
= RHS
ii. To prove that X + ( X . Y ) = X – Absorption law
LHS X + ( X . Y )
en
=(X+X).(X+Y) (Distribution of addition over multiplication)
=X.(X+Y) (Idempotent law)
=X. X+X.Y (Distribution of multiplication over addition)
=X+X.Y (Idempotent law)
=X.(1+Y) (Distribution of multiplication over addition)
=X.1
=X
= RHS im
(Additive identity)
(Multiplicative identity)
64
2. Data Representation and Boolean Algebra
en
(i) “the complement of sum of Boolean variables is equal to product of their
individual complements” and
(ii) “the complement of product of Boolean variables is equal to sum of their
individual complements”.
Algebraic proof of the first theorem
We have to prove that, X + Y = X . Y
im
Let us assume that, Z = X + Y ______ (1)
Then, Z = X + Y ______ (2)
We know that, by complimentary law, the equations (3) and (4) are true.
Z + Z = 1 ______ (3)
c
Z . Z = 0 ______ (4)
Substituting expressions (1) in (3) and (2) in (4), we will get equations (5) and (6).
e
(X + Y) + ( X + Y ) = 1 ______ (5)
(X + Y) . ( X + Y ) = 0 ______ (6)
For the time being let us assume that De Morgan’s first theorem is true. If so, ( X + Y )
p
in equations (5) and (6) can be substituted with ( X . Y ). Thus equations (5) and (6) can
be modified as follows:
(X+ Y) + ( X . Y ) = 1 ______ (7)
S
(X + Y) . ( X . Y ) = 0 ______ (8)
Now we will prove equations (7) and (8) separately. If they are correct, we can conclude
that the assumptions we made to form those equations are also correct. That is, if
equations (7) and (8) are true, De Morgan’s theorem is also true.
Consider the LHS of equation (7),
(X + Y) + ( X . Y ) = (X + Y + X ) . (X + Y + Y ) (Distributive Law)
= (X + X + Y) . (X + Y + Y ) (Associative Law)
= (1 + Y) . (X + 1) (Complimentary Law)
65
=1.1 (Additive Identity)
=1
= RHS
Now, let us consider the LHS of equation (8),
(X + Y) . ( X . Y ) = (X . X . Y ) + (Y . X . Y ) (Distributive Law)
en
= (X . X . Y ) + (Y . Y . X ) (Associative Law)
= (0 . Y ) + (0 . X ) (Complimentary Law)
=0+0 (Multiplicative Identity)
=0
= RHS
im
We have algebraically proved equations (7) and (8), which mean that De Morgan’s first
theorem is proved. The theorem can also be proved using truth table, but it is left to
you as an exercise.
Algebraic proof of the second theorem
We have to prove that, X. Y = X + Y
Let us assume that, Z = X . Y ______ (1)
c
Then, Z = X. Y ______ (2)
We know that, by complimentary laws the equations (3) and (4) are true.
e
Z + Z = 1 ______ (3)
Z . Z = 0 ______ (4)
p
Substituting expressions (1) in (3) and (2) in (4), we will get the expressions (5) and (6).
(X . Y) + ( X. Y ) = 1 ______ (5)
(X . Y) . ( X. Y ) = 0 ______ (6)
S
For the time being let us assume that De Morgan’s second theorem is true. If so,
( X. Y ) in equations 5 and 6 can be substituted with ( X + Y ). Thus equations (5) and
(6) can be modified as follows:
(X . Y) + ( X + Y ) = 1 ______ (7)
(X . Y) . ( X + Y ) = 0 ______ (8)
Now we will prove equations (7) and (8) separately. If they are correct, we can conclude
that the assumptions we made to form those equations are also correct. That is, if
equations (7) and (8) are true, De Morgan’s theorem is also true.
66
2. Data Representation and Boolean Algebra
en
=1.1 (Additive Identity)
=1
= RHS
Now, let us consider the LHS of equation (8),
(X . Y) . ( X + Y ) = (X . Y . X ) + (X . Y . Y ) (Distributive Law)
=0+0
=0
im
= (X . X . Y ) + (X . Y . Y )
= (0 . Y) + (X . 0)
(Associative Law)
(Complimentary Law)
(Multiplicative Identity)
= RHS
c
We have algebraically proved equations (7) and (8), which mean that De Morgan’s
second theorem is proved. The theorem can also be proved using truth table, but it is
left to you as an exercise.
e
A B C D ...... = A . B . C . D . …….
A.B.C.D...... = A + B + C + D + …….
S
67
Check yourself
1. Find the dual of Boolean expression A.B+B.C=1
2. Name the law which states that A+A=A.
(a) Commutative law (b) Idempotent Law (c) Absorption Law
3. State De Morgan's theorems.
en
2.9 Circuit designing for simple Boolean expressions
By using basic gates, circuit diagrams can be designed for Boolean expressions. We
have seen that the Boolean expressions A.B is represented using an AND gate, A+B
is represented using an OR gate and A is represented using a NOT gate. Let us see
im
how a circuit is designed for other Boolean expressions.
Consider a boolean expression A + B , which is
an OR operation with two input and first input
is inverted. So circuit diagram can be drawn as
Fig 2.12 : f (A, B) = A+B
shown in Figure 2.12.
Example: Construct a logical expression
c
Example: Construct a logical circuit for
Boolean expression f (X, Y) = X.Y + Y for f (a, b) = (a + b) . ( a + b )
e
p
68
2. Data Representation and Boolean Algebra
en
This is an AND gate with its output inverted by a NOT gate. The logical circuit
arrangement is shown in Figure 2.16.
Note that A and B are the inputs of
AND gate and its output is (A.B). The
output of AND gate is inverted by an Fig. 2.16 : Circuit realisation of NAND gate
im
inverter (NOT gate) to get the resultant output Y as
(A.B) . So the logical expression for a NAND gate is
(A.B) . From the truth table shown as Table 2.26, wee
can see that output of a NAND gate is 1 if any one
A
0
0
1
B
0
1
0
Y =
(A.B)
1
1
1
of the input is 0. It produces output 0 if and only if
1 1 0
c
all inputs are 1. This is the inverse operation of an
Table 2.26 : NAND truth table
AND gate. So we can say that a NAND gate is an
inverted AND gate.
e
69
From the truth table shown on as Table 2.27, we A B Y= (A + B)
can see that output of a NOR gate is 1 if and only if 0 0 1
all inputs are 0. If any one of the inputs is 1 it
0 1 0
produces an output 0. This is the inverse operation
1 0 0
of an OR gate. So we can say that a NOR gate is
an inverted OR gate. 1 1 0
Table 2.27 : NOR truth table
en
The logical symbol of NOR gate is shown in Figure 2.19.
Note that the NOR symbol is an OR symbol with a
small bubble at the output.
2.10.3 Implementation of basic gates using Fig. 2.19 : NOR gate
NAND and NOR
im
We can design all basic gates (AND, OR and NOT) using NAND or NOR gate alone.
Let us see the implementation of basic gates using NAND gate.
NOT gate using NAND gate
We can implement a NOT gate (inverter) using a NAND by applying the same signal
to both inputs of a NAND gate as shown in Figure 2.20.
c
e
=A Since A.A = A
A AA (A.A) A
The truth table shown as Table 2.28 is the 0 0 1 1
proof for obtaining NOT gate using NAND 1 1 0 0
S
70
2. Data Representation and Boolean Algebra
Proof
en
= ( (AB) ) Since A.A = A
= A.B Since (A) = A
Table 2.29 shows the proof for obtaining AND gate using NAND gate with the help
of the truth table.
A B A.B (A.B) (A.B) . (A.B)
0
0
1
1
0
1
0
1
0
0
0
1
1
1
1
0
im 1
1
1
0
((AB) . (AB) )
0
0
0
1
Table 2.29 : Proof using truth table
c
OR gate using NAND gate
The OR gate is replaced by a NAND gate with all its inputs complemented by NAND
gate inverters as shown in Figure 2.22.
e
p
A NAND A = ( A.A)
=A
Similarly, B NAND B =B
Therefore, (A NAND A) NAND (B NAND B) = A NAND B
= ( A .B )
= A + B Since ( A.B) = A + B
71
Table 2.30 shows the proof for obtaining OR gate using NAND gate with the help of
truth table.
A B A B A .B (A.B) A+B
0 0 1 1 1 0 0
0 1 1 0 0 1 1
1 0 0 1 0 1 1
en
1 1 0 0 0 1 1
Table 2.30 : Proof using truth table
Thus, the NAND gate is a universal gate since it can implement AND, OR and NOT
operations. Now let us see implementation of basic gates by using another universal
gate, the NOR gate.
im
NOT gate using NOR gate
We can implement a NOT gate (inverter) using a NOR by applying the same signal to
both inputs of a NOR gate as shown in Figure 2.23.
Proof:
A NOR A = ( A + A)
c
= A Since A+A=A Fig 2.23 : NOT gate using NOR gate
truth table. 0 0 1 1
1 1 0 0
OR gate using NOR gate Table 2.31 : Proof using truth table
p
72
2. Data Representation and Boolean Algebra
= (( A + B )) Since A+A=A
= A+B Since ( A ) =A
Table 2.32 shows the proof of obtaining OR gate using NOR gate with the help of the
truth table.
A B A+B ( A + B ) ( A + B ) + (A.B) ((A + B) . (A + B) )
en
0 0 0 1 1 0
0 1 1 0 0 1
1 0 1 0 0 1
1 1 1 0 0 1
Table 2.32 : Proof using truth table
AND gate using NOR gate
im
The AND gate is replaced by a NOR gate with all its inputs complemented by NOR
gate inverters as shown in Figure 2.25.
c
Fig. 2.25 : AND gate using NOR gate
e
Proof
A NOR A = ( A.A ) =A
Similarly, B NOR B =B
p
= ( A ) . ( B ) Since ( A + B )= A . B
= A.B Since A =A
Thus, the NOR gate is also a A B A B A +B A.B
(A + B)
universal gate since it can
implement the AND, OR and 0 0 1 1 1 0 0
NOT operations. Table 2.33 0 1 1 0 1 0 0
represents the proof for 1 0 0 1 1 0 0
obtaining AND gate using 1 1 0 0 0 1 1
NOR gate with the help of
truth table. Table 2.33 : Proof using truth table
73
Check yourself
1. Draw logic circuits for the Boolean expression X+ Y .
2. Which gates are called universal gates?
3. ______ gate produces low (0) output if any one of the input is
high(1)
en
(a)OR (b) AND (c) NAND (d) NOR
4. A NAND B = —————— .
(a) A+B (b) A.B (c) ( A + B ) (d) ( A.B )
Let us sum up
im
Different methods of data representation were discussed in this chapter. Before
discussing data representation of numbers, we introduced different number
systems and their conversions. After the discussion of integer and floating
point number representation we have mentioned different methods for
character, sound, image and sound data representation. We have also discussed
the concept of Boolean algebra in detail including logical operators, logic gates
c
and laws of Boolean algebra. We concluded the chapter by introducing methods
for designing basic logic circuits and by discussing the importance of universal
gates in circuit designing.
e
Learning outcomes
p
74
2. Data Representation and Boolean Algebra
Sample questions
Very short answer type
1. What is the place value of 9 in (296)10 ?
2. Find octal equivalent of the decimal number 55.
3. Find missing terms in the following series
en
a) 1012 , 10102, 11112, ______, _______
b) 158 , 168, 178, ______, ______.
c) 1816, 1A16, 1C16 ,_____, ______.
4. If (X)2 - (1010)2 = (1000)2 then find X.
5. Name the coding system that can represent almost all the characters used in the
im
human languages in the world.
6. Find out the logical statement(s) from the following .
a) Why are you late?
b) Will you come with me to market ?
c) India is my country.
d) Go to class room.
c
7. List three basic logic gates.
8. Which gate is called inverter?
9. List two complimentarity Laws.
e
3. Convert the following numbers into the other three number systems:
a) (125)8 b) 98 c) (101110)2 d) (A2B)16
4. Find the equivalents of the given numbers in the other three number systems.
a) (7F.1)16 b) (207.13)8 c) 93.25 d) (10111011.1101)2
5. If (X)2 = (Y)8 = (Z)16 = (28)10 Then find X, Y and Z.
6. Arrange the following numbers in descending order
a) (101)16 b) (110)10 c) (111000)2 d) (251)8
7. Find X , if (X)2 = (10111)2 + (11011)2 - (11100)2
75
8. What are the methods of representing integers in computer memory?
9. Represent the following numbers in sign and magnitude method, 1’s complement
method and 2’s complement method
a) -19 b) +49 c) -97 d) -127
10. Find out the integer which is represented as (10011001)2 in sign and magnitude
method.
en
11. Explain the method of representing a floating point number in 32 bit computer.
12. What are the methods of representing characters in computer memory?
13. Briefly explain the significance of Unicode in character representation.
14. Match the following:
A B
i)
ii)
iii)
iv)
If any input is 1 output is 1
If an input is 0 output is 0
If any input is 0 output is 1
If any input is 1 output is 0
im
a)
b)
c)
d)
NAND
OR
NOR
AND
c
15. Find dual of following Boolean expressions
a) X.Y+Z b) A.C+A.1+A.C c) (A+0).(A.1. A )
16. Find complement of following Boolean expressions
e
a) A B b) A.B + C.D
17. Construct logic circuit for the following Boolean expression.
p
76