Digital Logic Design (MITS-DU) PDF
Document Details
Uploaded by CoolPlatinum1768
Madhav Institute of Technology and Science
Dr. Abhishek Dixit
Tags
Summary
This document provides lecture notes on digital logic design. It covers fundamental concepts, applications, and historical context. The document is suitable for undergraduate-level study in computer engineering or computer science.
Full Transcript
Digital Logic Design (25241104) Dr. Abhishek Dixit Assistant Professor...
Digital Logic Design (25241104) Dr. Abhishek Dixit Assistant Professor Deptt. of CSBS, MITS-DU Madhav Institute of Technology & Science, Gwalior-Deemed University DIGITAL LOGIC DESIGN/DIGITAL ELECTRONICS Digital Logic Design is foundational to the fields of electrical engineering and computer engineering. Digital Logic Design is used to develop hardware, such as circuit boards and microchip processors. This hardware processes user input, system protocol and other data in computers, navigational systems, cell phones or other high-tech systems. OR Digital electronics are electronic fields that include the area of digital signals and engineering elements that yields high productivity. It is comprised of multiple logic gates packed as integrated circuits. Madhav Institute of Technology & Science, Gwalior-Deemed University DIGITAL LOGIC DESIGN AND ITS IMPORTANCE Most of electronic devices consist of two integrated systems Electronic Devices Hardware Software Circuits that execute the program Programs that control hardware to commands execute user wishes To learn more about how to To learn how to design this design this you need to study you need to study Computer Digital Logic Design Science Madhav Institute of Technology & Science, Gwalior-Deemed University CONCLUSION How a program 'actually works' inside a machine, you must know in DLD/DE. Computer Engineer (means if you think computer engineering means software development only) it might be usefull for those who are/will working/work in IBM or intel or amd or nvidia where they design processor. A Computer Science is a study of both software and hardware (Over here hardware doesn't mean Motherboard or mouse or keyboard but Hardware means CPU i.e. ALU + MU) you are supposed to learn how things internally work in Computer and as ALU is Build using adder, substractor, etc while MU is build of large quantity Flip Flop packed in few IC ( Integrated Circuits ) for data storage. It gives you a clear understanding of how exactly everything works and how processing is done in ALU. - Quora Madhav Institute of Technology & Science, Gwalior-Deemed University APPLICATIONS OF DIGITAL LOGIC DESIGN Conventional computer design CPUs, busses, peripherals Networking and communications Phones, modems, routers Embedded products Cars Toys Appliances Entertainment devices: MP3 players, gaming consoles Madhav Institute of Technology & Science, Gwalior-Deemed University HOW DID IT ALL START? 1850: George Boole invents Boolean algebra (Boolean algebra is a branch of mathematics that deals with logical operations using binary variables) Madhav Institute of Technology & Science, Gwalior-Deemed University 1946: ENIAC, the first electronic computer is developed Vacuum Tubes The first generation computers used vacuum tubes for circuitry and magnetic drums for memory, and were often enormous, taking up entire rooms. The vacuum tube was developed by Lee De Forest. The vacuum tube is a glass tube with its gas removed, creating a vacuum. Vacuum tubes contain electrodes for controlling electron flow and were used in early computers as a switch or an amplifier. Madhav Institute of Technology & Science, Gwalior-Deemed University 1947: Shockley, Brattain, and Bardeen invent the transistor Replaces vacuum tubes Enables integration of multiple devices into one package AND … Madhav Institute of Technology & Science, Gwalior-Deemed University 1955: TRADIC: AT&T Bell Labs announced the first fully transistorized computer AND … Madhav Institute of Technology & Science, Gwalior-Deemed University 1971: Intel’s 4004 first microprocessor Madhav Institute of Technology & Science, Gwalior-Deemed University NUMBER SYSTEM In digital electronics, the number system is used for representing the information. The number system has different bases and the most common of them are the decimal, binary, octal, and hexadecimal. The base or radix of the number system is the total number of the digit used in the number system. Number systems are the technique to represent numbers in the computer system architecture, every value that you are saving or getting into/from computer memory has a defined number system. Computer architecture supports following number systems. Binary number system Octal number system Decimal number system Hexadecimal (hex) number system Madhav Institute of Technology & Science, Gwalior-Deemed University BINARY NUMBER SYSTEM A Binary number system has only two digits that are 0 and 1. Every number (value) represents with 0 and 1 in this number system. The base of binary number system is 2, because it has only two digits. DECIMAL NUMBER SYSTEM Decimal number system has only ten (10) digits from 0 to 9. Every number (value) represents with 0,1,2,3,4,5,6,7,8 and 9 in this number system. The base of decimal number system is 10, because it has only 10 digits. Madhav Institute of Technology & Science, Gwalior-Deemed University OCTAL NUMBER SYSTEM Octal number system has only eight (8) digits from 0 to 7. Every number (value) represents with 0,1,2,3,4,5,6 and 7 in this number system. The base of octal number system is 8, because it has only 8 digits. HEXADECIMAL NUMBER SYSTEM A Hexadecimal number system has sixteen (16) alphanumeric values from 0 to 9 and A to F. Every number (value) represents with 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F in this number system. The base of hexadecimal number system is 16, because it has 16 alphanumeric values. Here A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15. Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University Number System Conversions Madhav Institute of Technology & Science, Gwalior-Deemed University BINARY TO DECIMAL CONVERSION Multiply the digit with 2(with place value exponent). Eventually add all the multiplication becomes the Decimal number. Convert Binary Number 110011 to a Decimal Number: Binary 1 1 0 0 1 1 Decimal 32 + 16 + 0 + 0 + 2 + 1 = 51 Madhav Institute of Technology & Science, Gwalior-Deemed University (ii) Convert (111.101)2 to decimal. Solution: (111.101)2 = (1 x 22) + (1 x 21) + ( 1x 20 ) + ( 1 x 2 -1 ) + (0 x 2 -2) + (1 x 2 -3) = 4 + 2+ 1 + 0.5 + 0 + 0.125 = (7.625)10 Madhav Institute of Technology & Science, Gwalior-Deemed University BINARY TO OCTAL CONVERSION An easy way to convert from binary to octal is to group binary digits into sets of three, starting with the least significant (rightmost) digits. Convert Binary Number 110011 to a Octal Number: Binary 1 1 0 0 1 1 Octal 6 3 = 63 Convert Binary Number 11100101 to a Octal Number: Binary 0 1 1 1 0 0 1 0 1 Octal 3 4 5 = 345 Madhav Institute of Technology & Science, Gwalior-Deemed University Convert (101111010110.110110011)2 into octal. Solution : Group of 3 bits are 101 111 010 110. 110 110 011 Convert each group into octal = 5 7 2 6. 6 6 3 The result is (5726.663)8 Convert (10101111001.0111)2 into octal. Solution : Binary number 10 101 111 001. 011 1 Group of 3 bits are = 010 101 111 001. 011 100 Convert each group into octal = 2 5 7 1. 3 4 The result is (2571.34)8 Madhav Institute of Technology & Science, Gwalior-Deemed University BINARY TO HEXADECIMAL CONVERSION An equally easy way to convert from binary to hexadecimal is to group binary digits into sets of four, starting with the least significant (rightmost) digits. Convert Binary Number 110011 to a Hexadecimal Number: Binary 1 1 0 0 1 1 Hexadecimal 3 3 = 33 Convert Binary Number 11100101 to a Hexadecimal Number: Binary 1 1 1 0 0 1 0 1 Hexadecimal E 5 = E5 Madhav Institute of Technology & Science, Gwalior-Deemed University Convert (1011011011)2 into hexadecimal. Solution: Given Binary number 10 1101 1011 Group of 4 bits are 0010 1101 1011 Convert each group into hex = 2 D B The result is (2DB)16 Convert (01011111011.011111)2 into hexadecimal. Solution: Given Binary number 010 1111 1011. 0111 11 Group of 4 bits are = 0010 1111 1011. 0111 1100 Convert each group into octal = 2 F B. 7 C The result is (2FB.7C)16 Madhav Institute of Technology & Science, Gwalior-Deemed University DECIMAL TO OTHER BASE SYSTEM CONVERSION To convert Number system from Decimal Number System to Any other Base you have to follow just two steps: STEP 1: Divide the Number (Decimal Number) by the base of target base system (in which you want to convert the number: Binary (2), octal (8) and Hexadecimal (16)). STEP 2: Write the remainder from step 1 as a Least Signification Bit (LSB) to Step last as a Most Significant Bit (MSB). Madhav Institute of Technology & Science, Gwalior-Deemed University DECIMAL TO BINARY CONVERSION Divide by 2 Decimal # 13 ÷ 2 = 6 remainder 1 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 1 1 0 1 Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University DECIMAL TO OCTAL CONVERSION Divide by 8 Madhav Institute of Technology & Science, Gwalior-Deemed University DECIMAL TO HEXADECIMAL CONVERSION Divide by 16 Decimal # 47 ÷ 16 = 2 remainder 15 2 ÷ 16 = 0 remainder 2 2 F Madhav Institute of Technology & Science, Gwalior-Deemed University DECIMAL TO HEXADECIMAL CONVERSION Divide by 16 Madhav Institute of Technology & Science, Gwalior-Deemed University HEXADECIMAL TO BINARY CONVERSIONS Converting from hexadecimal to binary is as easy as converting from binary to hexadecimal. Simply look up each hexadecimal digit to obtain the equivalent group of four binary digits. Hexadecimal C 3 Binary 1100 0011 Madhav Institute of Technology & Science, Gwalior-Deemed University HEXADECIMAL TO DECIMAL CONVERSION Convert hexadecimal number 2DB to a decimal number Hexadecimal 2 D B (256 x 2) (16 x 13) (1 x 11) Decimal 512 + 208 + 11 = 731 Madhav Institute of Technology & Science, Gwalior-Deemed University OCTAL TO BINARY CONVERSION Converting from octal to binary is as easy as converting from binary to octal. Simply look up each octal digit to obtain the equivalent group of three binary digits. Octal 3 4 5 Binary 011 100 101 Madhav Institute of Technology & Science, Gwalior-Deemed University OCTAL TO HEXADECIMAL CONVERSION When converting from octal to hexadecimal, it is often easier to first convert the octal number into binary and then from binary into hexadecimal. For example, to convert 345 octal into hex: Octal 3 4 5 Binary 011 100 101 Hex 0 E 5 Madhav Institute of Technology & Science, Gwalior-Deemed University OCTAL TO DECIMAL CONVERSION The conversion can also be performed in the conventional mathematical way, by showing each digit place as an increasing power of 8. 345 octal = (3 * 82) + (4 * 81) + (5 * 80) = (3 * 64) + (4 * 8) + (5 * 1) = 229 decimal Madhav Institute of Technology & Science, Gwalior-Deemed University SIGNED AND UNSIGNED NUMBERS Madhav Institute of Technology & Science, Gwalior-Deemed University Unsigned binary numbers are, by definition, positive numbers and thus do not require an arithmetic sign. An m-bit unsigned number represents all numbers in the range 0 to 2m − 1. Signed numbers require an arithmetic sign. The most significant bit of a binary number is used to represent the sign bit. If the sign bit is equal to zero, the signed binary number is positive; otherwise, it is negative. The remaining bits represent the actual number. There are three ways to represent negative numbers. Represented by range (– 2m-1 +1) to (2m-1 − 1). 1. Sign-Magnitude Representation In the sign-magnitude representation method, a number is represented in its binary form. The most significant bit (MSB) represents the sign. A 1 in the MSB bit position denotes a negative number; a 0 denotes a positive number. The remaining n −1 bits are preserved and represent the magnitude of the number. The following examples illustrate the sign-magnitude representation: Madhav Institute of Technology & Science, Gwalior-Deemed University COMPLEMENT 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. Radix Complement The radix complement is referred to as the r's complement Diminished Radix Complement The diminished radix complement is referred to as the (r-1)'s complement Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University 1’s COMPLEMENT The 1’s complement of a binary number is obtained by changing each 0 to 1 and each 1 to 0. For example Find (1100)2 1’s complement. Solution :- Given 1 1 0 0 1’s complement is 0 0 1 1 Result is (0011)2 Madhav Institute of Technology & Science, Gwalior-Deemed University 2’s COMPLEMENT The 2’s complement of a binary number is a binary number which is obtained by adding 1 to the 1’s complement of a number i.e. 2’s complement = 1’s complement + 1 For example Find (1010)2 2’s complement. Solution Given 1 0 1 0 1’s complement is 0 1 0 1 +1 2’s complement 0110 Result is (0110) Madhav Institute of Technology & Science, Gwalior-Deemed University 9's & 10's COMPLEMENT If the number is binary, then we use 1's complement and 2's complement. But in case, when the number is a decimal number, we will use the 9's and 10's complement. The 10's complement is obtained from the 9's complement of the number, and we can also find the 9's and 10's complement using the r's and (r-1)'s complement formula. Madhav Institute of Technology & Science, Gwalior-Deemed University 9’s COMPLEMENT The 9’s complement of a decimal number is obtained by subtracting each digit of the number by 9. For example Find (1423)10 9’s complement. Solution Given 1423 9’s complement is 9999 - 1423 8576 Result is (8576) 10 Madhav Institute of Technology & Science, Gwalior-Deemed University 10’s COMPLEMENT The 10’s complement of a decimal number is a decimal number which is obtained by adding 1 to the 9’s complement of a number i.e. 10’s complement = 9’s complement + 1 For example Find (1423)10 10’s complement. Solution Given 1423 9’s complement is 8576 (9999-1423) +1 10’s complement 8577 Result is (8577) 10 Madhav Institute of Technology & Science, Gwalior-Deemed University 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 Madhav Institute of Technology & Science, Gwalior-Deemed University 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) Let us take two binary numbers 10001001 and 10010101 and ADD them Tell the Answer… 100011110 Madhav Institute of Technology & Science, Gwalior-Deemed University Binary Subtraction There are four steps in binary subtraction, they are written below 0–0=0 0 – 1 = 1, borrow 1 from the next more significant bit 1–0=1 1–1=0 Let us take two binary numbers 110110 – 10110 Tell the Answer… 100000 Madhav Institute of Technology & Science, Gwalior-Deemed University Binary Multiplication There are four steps in binary multiplication, they are written below 0×0=0 1×0=0 0×1=0 1×1=1 (there is no carry or borrow for this) Let us take two binary numbers 1001* 101 Tell the Answer… 101101 Madhav Institute of Technology & Science, Gwalior-Deemed University 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. Madhav Institute of Technology & Science, Gwalior-Deemed University Subtraction using 1's complement In 1’s complement subtraction, add the 1’s complement of subtrahend to the minuend. If there is a carry out, then the carry is added to the LSB. This is called end around carry. If the MSB is 0, the result is positive. If the MSB is 1, the result is negative and is in its 1‘s complement form. Then take its 1’s complement to get the magnitude in binary. In other words: Step: 1. Write the first number (minuend) as such. 2. Write the 1’s complement of second number(subtrahend) 3. Add the two numbers. 4. The carry that arises from the addition is said to be “end around carry”. 5. End-around carry should be added with the sum to get the result. 6. If there is no end around carry find out the 1’s complement of the sum and put a negative sign before the result as the result is negative. Madhav Institute of Technology & Science, Gwalior-Deemed University For example Subtract (10000)2 from (11010)2 using 1’s complement. Solution 11010 11010 = 26 -10000 => + 0 1 1 1 1 (1’s complement) = - 16 Carry → 1 0 1 0 0 1 +10 +1 01010 = +10 Result is +10 Example 2: 10101 - 10111 Madhav Institute of Technology & Science, Gwalior-Deemed University Addition using 1's complement Case 1: Addition of the positive number with a negative number when the positive number has a greater magnitude. Initially, calculate the 1's complement of the given negative number. Sum up with the given positive number. If we get the end-around carry 1, it gets added to the LSB. Example: 1101 and -1001 Case 2: Adding a positive value with a negative value in case the negative number has a higher magnitude. Initially, calculate the 1's complement of the negative value. Sum it with a positive number. In this case, we did not get the end-around carry. So, take the 1's complement of the result and put a negative sign before the result as the result is negative to get the final result. Example: 1101 and - 1110 Case 3: Addition of two negative numbers In this case, first find the 1's complement of both the negative numbers, and then we add both these complement numbers. In this case, we always get the end-around carry, which get added to the LSB, and for getting the final result, we take the 1's complement of the result and put a negative sign before the result as the result is negative to get the final result. Example: -1101 and -1110 in five-bit register Madhav Institute of Technology & Science, Gwalior-Deemed University Addition using 1's complement Case 1: Addition of the positive number with a negative number when the positive number has a greater magnitude. Example: 1101 and -1001 1. First, find the 1's complement of the negative number 1001. So, for finding 1's complement, change all 0 to 1 and all 1 to 0. The 1's complement of the number 1001 is 0110. 2. Now, add both the numbers, i.e., 1101 and 0110; 1101+0110=1 0011 3. By adding both numbers, we get the end-around carry 1. We add this end around carry to the LSB of 0011. 0011+1=0100 Madhav Institute of Technology & Science, Gwalior-Deemed University Addition using 1's complement Case 2: Adding a positive value with a negative value in case the negative number has a higher magnitude. Example: 1101 and -1110 1. First find the 1's complement of the negative number 1110. So, for finding 1's complement, we change all 0 to 1, and all 1 to 0. 1's complement of the number 1110 is 0001. 2. Now, add both the numbers, i.e., 1101 and 0001; 1101+0001= 1110 3. Now, find the 1's complement of the result 1110 that is the final result. So, the 1's complement of the result 1110 is 0001, and we add a negative sign before the number so that we can identify that it is a negative number. Madhav Institute of Technology & Science, Gwalior-Deemed University Addition using 1's complement Case 3: Addition of two negative numbers Example: -1101 and -1110 in five-bit register 1. Firstly find the 1's complement of the negative numbers 01101 and 01110. So, for finding 1's complement, we change all 0 to 1, and all 1 to 0. 1's complement of the number 01110 is 10001, and 01101 is 10010. 2. Now, we add both the complement numbers, i.e., 10001 and 10010; 10001+10010= 1 00011 3. By adding both numbers, we get the end-around carry 1. We add this end-around carry to the LSB of 00011. 00011+1=00100 4. Now, find the 1's complement of the result 00100 that is the final answer. So, the 1's complement of the result 00100 is 110111, and add a negative sign before the number so that we can identify that it is a negative number. Madhav Institute of Technology & Science, Gwalior-Deemed University Subtraction using 2's complement In 2’s complement subtraction, add the 2’s complement of subtrahend to the minuend. If there is a carry out, ignore it. If the MSB is 0, the result is positive. If the MSB is 1, the result is negative and is in its 2‘s complement form. Then take its 2’s complement to get the magnitude in binary. In other words: Steps: 1. Write the first number as such 2. Write down the 2’s complement of the second number. 3. Add the two numbers. 4. If there is a carry, discard it and the remaining part (sum) will be the result (positive). 5. If there is no carry, find out the 2’s complement of the sum and put negative sign before the result as the result is negative. Madhav Institute of Technology & Science, Gwalior-Deemed University For example Subtract (1010100)2 from (1010100)2 using 2’s complement. Solution 1010100 1010100 = 84 -1010100 => + 0 1 0 1 1 0 0 (2’s complement) = - 84 Carry → 1 0 0 0 0 0 0 0 00 Hence MSB is 0. The answer is positive. So it is +0000000 = 0 Madhav Institute of Technology & Science, Gwalior-Deemed University Addition using 2's complement Case 1: Addition of the positive number with a negative number when the positive number has a greater magnitude. Initially find the 2's complement of the given negative number. Sum up with the given positive number. If we get the end-around carry 1 then the number will be a positive number and the carry bit will be discarded and remaining bits are the final result. Example: 1101 and -1001 Case 2: Adding a positive value with a negative value in case the negative number has a higher magnitude. Initially, add a positive value with the 2's complement value of the negative number. Here, no end- around carry is found. So, we take the 2's complement of the result to get the final result and put a negative sign before the result as the result is negative to get the final result. Example: 1101 and - 1110 Case 3: Addition of two negative numbers In this case, first, find the 2's complement of both the negative numbers, and then we will add both these complement numbers. In this case, we will always get the end-around carry, which will be discard, and forgetting the final result, we will take the2's complement of the result and put a negative sign before the result as the result is negative to get the final result. Example: -1101 and - 1110 in five-bit register Madhav Institute of Technology & Science, Gwalior-Deemed University Subtraction using 9's complement Case 1: When the subtrahend is smaller than the minuend. For subtracting the smaller number from the larger number using 9's complement, we will find the 9's complement of the subtrahend, and then we will add this complement value with the minuend. By adding both these values, the result will come in the formation of carry. At last, we will add this carry to the result obtained previously. Madhav Institute of Technology & Science, Gwalior-Deemed University Case 2: When the subtrahend is greater than the minuend. In this case, when we add the complement value and the minuend, the result will not come in the formation of carry. This indicates that the number is negative, and for finding the final result, we need to find the 9's complement of the result. Madhav Institute of Technology & Science, Gwalior-Deemed University Subtraction using 10's complement Case 1: When the subtrahend is smaller than the minuend. For subtracting the smaller number from the larger number using 10's complement, we will find the 10's complement of the subtrahend and then we will add this complement value with the minuend. By adding both these values, the result will come in the formation of carry. We ignore this carry and the remaining digits will be the answer. Madhav Institute of Technology & Science, Gwalior-Deemed University Case 2: When the subtrahend is greater than the minuend. In this case, when we add the complement value and the minuend, the result will not come in the formation of carry. This indicates that the number is negative and for finding the final result, we need to find the 10's complement of the result obtained by adding complement value of subtrahend and minuend. Madhav Institute of Technology & Science, Gwalior-Deemed University BINARY CODES In the coding, when numbers, letters or words are represented by a specific group of symbols, it is said that the number, letter or word is being encoded. The group of symbols is called as a code. The digital data is represented, stored and transmitted as group of binary bits. This group is also called as binary code. The binary code is represented by the number as well as alphanumeric letter. Madhav Institute of Technology & Science, Gwalior-Deemed University Classification of Binary Codes https://www.ascii-code.com/ Madhav Institute of Technology & Science, Gwalior-Deemed University Weighted Codes Weighted binary codes are those which obey the positional weighting principles, each position of the number represents a specific weight. There are different Binary coded Decimal(BCD) like 8421 code, 2421 code, 3321 code, 4221 code, 5211 code, 84-2-1 code, 74-2-1 code which comes under weighted code. Madhav Institute of Technology & Science, Gwalior-Deemed University Positional weighting principle Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Prof. Abhishek Dixit Gwalior-Deemed University 8421 BCD code (Natural BCD code) Each decimal digit 0 through 9 is coded by a 4 bit binary no. called natural binary codes. Because of the 8,4,2,1 weights attached to it. It is a weighted code & also sequential code. It is useful for mathematical operations. Advantage conversion to & from decimal. Disadvantage It is less efficient than the pure binary, it require more bits. Ex: 14→1110 in binary But as 0001 0100 in 8421 code. Arithmetic operations are more complex than they are in pure binary. There are 6 illegal combinations 1010,1011,1100,1101,1110,1111 in these codes, they are not part of the 8421 BCD code system. Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University BCD Addition If there is an illegal code or carry is generated as a result of addition, then add 0110 to particular that 4 bits of result. Madhav Institute of Technology & Science, Gwalior-Deemed University Prof. Abhishek Dixit Madhav Institute of Technology & Science, Gwalior-Deemed University BCD Subtraction If one 4 bits group needs to take borrow from neighbour, then subtract 0110 from the group which is receiving borrow. Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University Non - Weighted codes In this code, no weight is assigned to any of the bit positions. Bits will not have any fixed value based on their position. Excess-3 code and gray code are the examples of non-weighted code. Excess-3 code The excess-3 code (or XS3) is a non-weighted code used to express decimal numbers. It is a self-complementary binary coded decimal (BCD) code and numerical system which has biased representation. It is particularly significant for arithmetic operations as it overcomes shortcoming encountered while using 8421 BCD code to add two decimal digits whose sum exceeds 9. Excess three code = 8421 BCD Code + 0011 The xs-3 code has six invalid states 0000,00001, 0010,1101,1110,1111. Madhav Institute of Technology & Science, Gwalior-Deemed University Representation of Excess-3 Code Excess-3 codes are unweighted and can be obtained by adding 3 to each decimal digit then it can be represented by using 4 bit binary number for each digit. An Excess-3 equivalent of a given binary number is obtained using the following steps: Find the decimal equivalent of the given binary number. Add +3 to each digit of decimal number. Convert the newly obtained decimal number back to binary number to get required excess-3 equivalent. Decimal Digit BCD Code Excess-3 Code 0 0000 0011 1 0001 0100 2 0010 0101 Madhav Institute of Technology & Science, Gwalior-Deemed University Excess-3 Addition: Add the xs-3 no.s by adding the 4 bit groups in each column starting from the LSD. If there is no carry starting from the addition of any of the 4-bit groups, subtract 0011 from the sum term of those groups ( because when 2 decimal digits are added in xs-3 & there is no carry , result in xs-6). If there is a carry out, add 0011 to the sum term of those groups( because when there is a carry, the invalid states are skipped and the result is normal binary). In simple word: Add 0011 to group which generated carry and subtract 0011 to group which do not generated carry. Madhav Institute of Technology & Science, Gwalior-Deemed University Excess -3 (XS-3) Subtraction: Subtract the xs-3 no.s by subtracting each 4 bit group of the subtrahend from the corresponding 4 bit group of the minuend starting form the LSD.if there is no borrow from the next 4-bit group add 0011 to the difference term of such groups (because when decimal digits are subtracted in xs-3 & there is no borrow , result is normal binary). I f there is a borrow , subtract 0011 from the difference term(bcoz taking a borrow is equivalent to adding six invalid states , result is in xs-6) In simple word: Subtract 0011 to group which generated borrow and add 0011 to group which do not generated borrow. Madhav Institute of Technology & Science, Gwalior-Deemed University Example 1 −Convert decimal number 23 to Excess-3 code. = 23+33=56 =0101 0110 which is required excess-3 code for given decimal number 23 Example 2 −Convert decimal number 15.46 into Excess-3 code. = 15.46+33.33=48.79 =0100 1000.0111 1001 which is required excess- 3 code for given decimal number 15.46. Example 3 − Convert Excess-3 code 1001001 into BCD and decimal number. grouping 4-bit for each group, i.e., 0100 1001 and subtract 0011 0011 from given number. Therefore, = 0100 1001 -0011 0011 =0001 0110 So, binary coded decimal number is 0001 0110 and decimal number will be 16. Madhav Institute of Technology & Science, Gwalior-Deemed University Gray Code It is a non-weighted code and known as unit- distance code. This is because, bit patterns for every consecutive number differ in only one bit position. These codes are also called cyclic codes. Madhav Institute of Technology & Science, Gwalior-Deemed University How to find a gray code from the given binary number? Write the MSB of the given binary code as the MSB of gray code and binary code are same. Perform an Ex-OR operation with the previous bit and the current bit to get the next gray digit. Ignore the carry, if any. Repeat 2nd step until all the binary bits have been Ex-ORed with their previous one. Let us look at an example here. Convert a binary number (101011)2 into its equivalent gray code. binary to gray code conversion Madhav Institute of Technology & Science, Gwalior-Deemed University How to find a binary number from the given gray code ? If an n-bit gray number is represented by Gn Gn-1 ------- G1 and its binary equivalent by Bn Bn-1 - - - - - B1, then binary bits are obtained from Gray bits as follows : Madhav Institute of Technology & Science, Gwalior-Deemed University Sequential Code A code is said to be sequential when two subsequent codes, seen as numbers in binary representation, differ by one. The 8421 and Excess-3 codes are sequential, whereas the 2421 and 5211 codes are not. Madhav Institute of Technology & Science, Gwalior-Deemed University Cyclic Code The successive code differs from each other by one bit position Madhav Institute of Technology & Science, Gwalior-Deemed University Self Complementing Code Madhav Institute of Technology & Science, Gwalior-Deemed University ASCII CODE The American Standard Code for Information Interchange (ASCII) pronounced as ‘ASKEE’ is widely used alphanumeric code. This is basically a 7 bit code. The number of different bit patterns that can be created with 7 bits is 27 = 128 , the ASCII can be used to encode both the uppercase and lowercase characters of the alphabet (52 symbols) and some special symbols in addition to the 10 decimal digits. It is used extensively for printers and terminals that interface with small computer systems. The table shown below shows the ASCII groups. Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University EBCDIC CODE The Extended Binary Coded Decimal Interchange Code (EBCDIC) pronounced as ‘eb – si- dik’ is an 8 bit alphanumeric code. Since 28 = 256 bit patterns can be formed with 8 bits. It is used by most large computers to communicate in alphanumeric data. Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University Madhav Institute of Technology & Science, Gwalior-Deemed University