RAJASTHAN TECHNICAL UNIVERSITY KOTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR

SUBJECT: DIGITAL ELECTRONICS

BRANCH: COMPUTER SCIENCE/INFORMATION TECHNOLOGY

YEAR/SEMESTER: II/III

FACULTY NAME:SUJEET KUMAR GUPTA SYLLABUS

Recommended books: T1 :- Modern Digital Electronics 4th Edition, R.P Jain: Tata Mcgraw-Hill T2 :- Digital Design [5th Edition] (M. Morris Mano and Michael Ciletti), Pearson T3 :- Digital Electronics, A.Anand , Pearson FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

UNIT 1

Fundamental Concept of Number System, Basic logic gates and Boolean algebra

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM BLOWN UP OF UNIT 1

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

NUMBER SYSTEMS AND CODES

Objectives :

•Binary, , Hexadecimal and BCD Number System. •Number Conversion

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Outcomes

At the end of this chapter, students should be able to:- – Differentiate between decimal, binary, octal, hexadecimal and BCD. – Convert number between bases.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

1.0 Types of Number System

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

1.1 List of Number

Type Base Numbers/Symbols

Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Binary 2 0, 1

Octal 8 0, 1, 2, 3, 4, 5, 6, 7

Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, , D, E, F

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

2.0 Binary Numbers

• Used to represent the voltage levels of a digital circuit. • Only two voltage levels present in a digital circuit, logic High and logic Low. • The high voltage is +5V and the low voltage is +0V. • The binary numbers represent the logic low as a 0 and the logic high as a 1.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

2.1 Decimal  Binary Conversion • A decimal number can be converted to a by successively dividing the number by 2 as follows:

•Note that the first remainder becomes the most significant (MSB). The last remainder becomes the least significant bit (LSB).

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Converting Fractional Decimal Number into Binary Number

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM Decimal  Octal Conversion

• A decimal number can be converted to an octal number by successively dividing the number by 8 as follows:

266 ‚ 8 = 33 remainder 2 LSD (right-most digit) 33 ‚ 8 = 4 remainder 1 4 ‚ 8 = 0 remainder 4 MSB (left-most digit).

• Therefore 26610 = 4128

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Decimal  Hexadecimal Conversion • A decimal number can be converted to hex number by successively dividing the number by 16 as follows:

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

2.2 Binary  Decimal Conversion • A binary number is converted to a decimal number by summing together the weights of various positions in the binary number which contain a 1. For example, 10101112 = 8710.

FACULTY NAME:SUJEET KUMAR GUPTA Binary to octal conversion

• A binary number is converted into an octal number by taking groups of 3 , starting from LSB, and replacing them with an octal digit. For example, 11 010 . 1102 = 3268

FACULTY NAME:SUJEET KUMAR GUPTA Binary to Hexadecimal conversion

 A binary number is converted into an octal number by taking groups of 4 bits, starting from LSB, and replacing them with a hex digit. For example, . 101111110101102 = 2FD616

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Octal  Decimal Conversion • To convert an octal number to a decimal number, multiply each octal value

by the weight of the digit and sum the results. For example, 4128 = 26610.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Octal  Binary Representation • Each octal digit can be represented by a 3-bit binary number as shown below:

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Octal Binary Conversion

 Conversion from octal to binary is very straightforward. Each octal digit is

replaced by 3-bit binary number. For example, 4728 = 100 111 0102.

 A binary number is converted into an octal number by taking groups of 3 bits, starting from LSB, and replacing them with an octal digit. For example, 11 010 . 1102 = 3268

FACULTY NAME:SUJEET KUMAR GUPTA Octal to Hexadecimal Conversion

• Step 1: Octal to Binary conversion • Step 2: Binary to Hexadecimal conversion

• For example, Step 1 : 4728 = 100 111 0102

• Step 2 : 100 111 0102 = 13A 16

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Hexadecimal Number

• The hexadecimal number uses base 16. It uses the digits 0 through 9 plus the letters A, B, C, D, E and F.

• The letter A stands for decimal 10, B for 11, C for 12, D for 13, E for 14 and F for 15.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Hexadecimal Number

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Hexadecimal  Decimal Conversion • To convert a hex number to a decimal number, multiply each hex value by

the weight of the digit and sum the results. For example, 1A716 = 42310.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM Hexadecimal Binary Conversion

• Each hex digit can be represented by a 4-bit binary number as shown above. Conversion from hex to binary is very straightforward. Each hex digit is replaced by 4-bit binary number.

 A binary number is converted into an octal number by taking groups of 4 bits, starting from LSB, and replacing them with a hex digit. For example, . 110101102 = 3268

FACULTY NAME:SUJEET KUMAR GUPTA Binary Arithmetic

• In binary number system there are only 2 digits 0 and 1, and any number can be represented by these two digits. The arithmetic of binary numbers means the operation of addition, subtraction, multiplication and division. Binary arithmetic operation starts from the least significant bit i.e. from the right most side. We will discuss the different operations one by one in the following. • Binary Addition • Binary Subtraction • Binary Multiplication • Binary Division

FACULTY NAME:SUJEET KUMAR GUPTA Binary Addition

• There are four steps in binary addition, they are written below • 0 + 0 = 0 • 0 + 1 = 1 • 1 + 0 = 1 • 1 + 1 = 0 (carry 1 to the next significant bit) • An example will help us to understand the addition process. Let us take two binary numbers 10001001 and 10010101

• The above example of binary arithmetic clearly explains the binary addition operation, the carried 1 is shown on the upper side of the operands.

FACULTY NAME:SUJEET KUMAR GUPTA Complements

• Complements are used in the digital computers in order to simplify the subtraction

operation and for the logical manipulations. For each radix-r system (radix r

represents base of number system) there are two types of complements.

S.N. Complement Description

1 Radix Complement The radix complement is referred to as the r's complement

2 Diminished Radix The diminished radix Complement complement is referred to as the (r-1)'s complement

FACULTY NAME:SUJEET KUMAR GUPTA Binary system complements

• As the binary system has base r = 2. So the two types of complements for the binary system are 2's complement and 1's complement.

• 1's complement

• The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's. This is called as taking complement or 1's complement. Example of 1's Complement is as follows.

FACULTY NAME:SUJEET KUMAR GUPTA Cont… • 2's complement • The 2's complement of binary number is obtained by adding 1 to the Least Significant Bit (LSB) of 1's complement of the number.

• 2's complement = 1's complement + 1

• Example of 2's Complement is as follows.

FACULTY NAME:SUJEET KUMAR GUPTA Binary Subtraction • Here are too four simple steps to keep in memory • 0 – 0 = 0 • 0 – 1 = 1, borrow 1 from the next more significant bit • 1 – 0 = 1 • 1 – 1 = 0 • Evaluate:

• (i) 110110 - 10110 • Solution: • The numbers of bits in the subtrahend is 5 while that of minuend is 6. We make the number of bits in the subtrahend equal to that of minuend by taking a `0’ in the sixth place of the subtrahend. • Now, 2’s complement of 010110 is (101101 + 1) i.e.101010. Adding this with the minuend. • 1 1 0 1 1 0 Minuend 1 0 1 0 1 0 2’s complement of subtrahend Carry over 1 1 0 0 0 0 0 Result of addition

• After dropping the carry over we get the result of subtraction to be 100000.

FACULTY NAME:SUJEET KUMAR GUPTA Binary Multiplication

• Binary multiplication may sound like it would be more difficult than binary addition or subtraction – but is actually a simple process. Here are the four steps to be followed, using the same binary numbers 10001001 and 10010101: • 0×0=0 • 1×0=0 • 0×1=0 • 1×1=1 (there is no carry or borrow for this) • The arithmetic of multiplying binary numbers is shown below:

FACULTY NAME:SUJEET KUMAR GUPTA Binary Division

• Binary division is comprised of other two binary arithmetic operations, multiplication and subtraction; an example will explain the operation more easily.

• Here 101 is the quotient and 1 is the remainder.

FACULTY NAME:SUJEET KUMAR GUPTA Different Types of Binary Codes

• Table of Contents • Introduction • Commonly used Binary Codes • Weighted Binary Systems – Binary Weights – 8421 Code or BCD Code – 2421 Code – 5211 Code – Reflective Code – Sequential Codes • Non-Weighted Codes – Excess-3 Code • Excess -3 Code Examples –

FACULTY NAME:SUJEET KUMAR GUPTA Commonly used Binary Codes

• Other than the 8421 code or BCD code, 2421 code, 5211 code, reflective code, sequential code, non-weighted code, excess-3 code and Grey code are some of the codes which are popularized. • Commonly used Binary Codes • Before going into the details of individual binary codes, let us quickly take a look at some of the commonly used Binary Codes. The following is the list: • 8421 Codes • 2421 Codes • 5211 Codes • Excess-3 Codes • Gray Codes • In the above list, the first three i.e. 8421, 2421 and 5211 are Weighted codes while the other two are non-weighted binary codes.

FACULTY NAME:SUJEET KUMAR GUPTA Weighted Binary Systems

• The values assigned to consecutive places in the decimal system which is a place value system are 10⁴, 10³, 10², 10¹, 10⁰, 10⁻¹, 10⁻², 10⁻³… from left to right. It is easily can be understood that the weight of digit of the decimal system is ‘10’. • For example (3546.25)₁₀ = 3 x 10³ + 5 x 10² + 4 x 10¹ + 6 x 10⁰ + 2 x 10⁻¹ + 5 x 10⁻² • In the same way the values assigned to consecutive places in the binary system which is also a place value system, but called as weighted binary system are 2⁴, 2³, 2², 2¹, 2⁰, 2⁻¹, 2⁻², 2⁻³… from left to right. It is easily can be understood that the weight of digit of the binary system is ‘2’. • For example : (1110110)₂ = 1 x 2⁶+ 1 x 2⁵ + 1 x 2⁴ + 0 x 2³ + 1 x 2² + 1 x 2¹ + 0 x 2⁰

• = 64 + 32 + 16 + 0 + 4 + 2 + 0 = (118)10

FACULTY NAME:SUJEET KUMAR GUPTA 8421 Code or BCD Code

• The decimal numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 can be expressed in Binary numbers as shown below. All these binary numbers again expressed in the last column by expanding into 4 bits. As per the weighted binary digits, the 4 Bit binary numbers can be expressed according to their place value from left to right as 8421 (2³ 2² 2¹ 2⁰ = 8421).

FACULTY NAME:SUJEET KUMAR GUPTA Cont….

DECIMAL NUMBER BINARY NUMBER 4 BIT EXPRESSION(8421)

0 0 0000

1 1 0001

2 10 0010

3 11 0011

4 100 0100

5 101 0101

6 110 0110

7 111 0111

8 1000 1000

9 FACULTY1001 NAME:SUJEET 1001 KUMAR GUPTA 2421 Code

• This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.

DECIMAL NUMBER BINARY NUMBER 2421 CODE

0 0 0000

1 1 0001

2 10 0010

3 11 0011

4 100 0100

5 101 1011

6 110 1100

7 111 1101

8 1000 1110 FACULTY NAME:SUJEET KUMAR GUPTA 9 1001 1111 5211 Code

• This code is also a 4 bit application code where the binary weights carry 5, 4, 2, 1 from left to right.

DECIMAL NUMBER BINARY NUMBER 5211 CODE

0 0 0000

1 1 0001

2 10 0011

3 11 0101

4 100 0111

5 101 1000

6 110 1010

7 111 1100 FACULTY NAME:SUJEET KUMAR GUPTA 8 1000 1110 Reflective Code

• It can be observed that in the 2421 and 5211 codes, the code for decimal 9 is the complement of the code for decimal 0, the code for decimal 8 is the complement of the code for decimal 1, the code for decimal 7 is the complement of the code for decimal 2, the code for decimal 6 is the complement of the code for decimal 3, the code for decimal 5 is the complement of the code for decimal 4, these codes are called as reflexive codes.Excess-3 is also reflective code. 8421 code is not a reflective code.

• The same can be observed in the following table:

FACULTY NAME:SUJEET KUMAR GUPTA Cont…

DECIMAL NUMBER DECIMAL NUMBER 2421 CODE 5211 CODE

0 0 0000 0000

1 1 0001 0001

2 10 0010 0011

3 11 0011 0101

4 100 0100 0111

5 101 1011 1000

6 110 1100 1010

7 111 1101 1100

FACULTY NAME:SUJEET 8 1000 KUMAR GUPTA 1110 1110 Sequential Codes

• Sequential codes are the codes in which 2 subsequent numbers in binary representation differ by only one digit. The 8421 and Excess-3 codes are examples of sequential codes. 2421 and 5211 codes do not come under sequential codes.

DECIMAL NUMBER BINARY NUMBER 8421 CODE EXCESS-3

0 0 0000 0011

1 1 0001 0100

2 10 0010 0101

3 11 0011 0110

4 100 100 0111

5 101 0101 1000

6 110 0110 1001

7 111 0111 1010 FACULTY NAME:SUJEET 8 1000KUMAR GUPTA 1000 1011 Non-Weighted Codes

• Some of the codes will not follow the weights of the sequence binary numbers these are called as non-weighted codes. ASCII code and Grey code are some of the examples where they are coded for some special purpose applications and they do not follow the weighted binary number calculations.

FACULTY NAME:SUJEET KUMAR GUPTA Excess-3 Code

• As mentioned above, some of the codes will not follow the binary weights, Excess- 3 code is an example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved by adding the number 3 to the 8421 code. It is the reflective code.

• For example to convert 15 to an excess-3 code, first 3 to be added to each digit as shown below.

FACULTY NAME:SUJEET KUMAR GUPTA Excess -3 Code Examples

• 1) Find the excess-3 code of (237.75)10 • 2) Find the decimal number of excess-3 number 110010100011.01110101.

• Sol:

• 1) The excess-3 code for (237)10 is obtained by adding 3 to all the digits individually, that is 2, 3 an • d 7 will become 5, 6 and 10 respectively. These 5, 6 and 10 decimals have to be converted into binary form and the result is 010101101010.

• The excess-3 code for (.75)10 is obtained by replacing 7 and 5 with 10 and 8 respectively by adding 3 to each digit. That is, the excess-3 code for (.75) ₁₀ is.10101000. • Combining the results of the integral and fractional parts, the excess-3 code for (237.75)₁₀ is 010101101010.10101000.

• 2) The excess-3 code is 110010100011.01110101 • By separating 4 bits as group the equivalent excess-3 code is given as 1100 1010 0011.0111 0101. • Subtracting 0011 from each four-bit group, we obtain the new number as: 1001 0111 0000.0100 0010.

• Therefore, the decimal equivalent is (970.42)10.

FACULTY NAME:SUJEET KUMAR GUPTA Gray Code

• The gray code is the code where one bit will be differed to the preceding number. For example, decimal numbers 13 and 14 are represented by gray code numbers 1011 and 1001, these numbers differ only in single position that is the second position from the right. In the same way first position on the left changes for 7 and 8 which are 0100 and 1100 and this is also called Unit-distance code. The gray code has very special place in digital electronics.

FACULTY NAME:SUJEET KUMAR GUPTA Cont..

DECIMAL NUMBER GRAY CODE

0 0000 0000

1 0001 0001

2 0010 0011

3 0011 0010

4 0100 0110

5 0101 0111

6 0110 0101

7 0111 0100

FACULTY NAME:SUJEET 8 KUMAR1000 GUPTA 1100 What is Error?

• Error is a condition when the output information does not match with the input information. During transmission, digital signals suffer from noise that can introduce errors in the binary bits travelling from one system to other. That means a 0 bit may change to 1 or a 1 bit may change to 0.

FACULTY NAME:SUJEET KUMAR GUPTA Error-Detecting codes &Error-Correcting codes

• Error-Detecting codes • Whenever a message is transmitted, it may get scrambled by noise or data may get corrupted. To avoid this, we use error-detecting codes which are additional data added to a given digital message to help us detect if an error occurred during transmission of the message. A simple example of error-detecting code is parity check. • Error-Correcting codes • Along with error-detecting code, we can also pass some data to figure out the original message from the corrupt message that we received. This type of code is called an error-correcting code. Error-correcting codes also deploy the same strategy as error-detecting codes but additionally, such codes also detect the exact location of the corrupt bit. • In error-correcting codes, parity check has a simple way to detect errors along with a sophisticated mechanism to determine the corrupt bit location. Once the corrupt bit is located, its value is reverted (from 0 to 1 or 1 to 0) to get the original message.

FACULTY NAME:SUJEET KUMAR GUPTA How to Detect and Correct Errors?

• To detect and correct the errors, additional bits are added to the data bits at the time of transmission. • The additional bits are called parity bits. They allow detection or correction of the errors. • The data bits along with the parity bits form a code word.

FACULTY NAME:SUJEET KUMAR GUPTA Parity Checking of Error Detection

• It is the simplest technique for detecting and correcting errors. The MSB of an 8- bits word is used as the parity bit and the remaining 7 bits are used as data or message bits. The parity of 8-bits transmitted word can be either even parity or odd parity.

• Even parity -- Even parity means the number of 1's in the given word including the parity bit should be even (2,4,6,....).

• Odd parity -- Odd parity means the number of 1's in the given word including the parity bit should be odd (1,3,5,....).

FACULTY NAME:SUJEET KUMAR GUPTA Cont..

• Use of Parity Bit • The parity bit can be set to 0 and 1 depending on the type of the parity required. • For even parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is even. Shown in fig. (a). • For odd parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is odd. Shown in fig. (b).

FACULTY NAME:SUJEET KUMAR GUPTA How Does Error Detection Take Place?

• Parity checking at the receiver can detect the presence of an error if the parity of the receiver signal is different from the expected parity. That means, if it is known that the parity of the transmitted signal is always going to be "even" and if the received signal has an odd parity, then the receiver can conclude that the received signal is not correct. If an error is detected, then the receiver will ignore the received byte and request for retransmission of the same byte to the transmitter.

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM Exercises

1. Convert decimal 23410 to a. binary b. BCD b. octal c. hexadecimal

2. Convert binary 10010111012 to a. decimal b. octal c. hexadecimal d. BCD

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM Exercises

3. Convert hexadecimal ABF216 to a. decimal b. binary c. octal d. BCD

4. Convert BCD 10010100100110001BCD to a. decimal b. octal c. hexadecimal d. binary

5. Convert number octal 5268 to a. decimal b. BCD c. hexadecimal d. binary

FACULTY NAME:SUJEET KUMAR GUPTA GLOBAL INSTITUTE OF TECHNOLOGY JAIPUR DIGITAL ELECTRONICS CSE/III SEM

Exercises

1. Convert the following number to the indicated base/code.

a) 11101.112 to decimal.

b) FED.4716 to octal.

c) 01101001BCD to binary.

d) 7548 to BCD.

e) 152.2510 to hexadecimal.

FACULTY NAME:SUJEET KUMAR GUPTA