CE1111 :Digital Logic Design lecture 01 Introduction Dr. Atef Ali Ibrahim Course Administration Instructor: Dr. Atef Ali Ibrahim E_mail: attif_ali2002@yahoo.com Office Place: (Room CS-25 ) Office Hrs: TA: Tutorial: Text Book: M. Morris Mano; “Digital Design”, 4thEdition, prentice hall. Prerequisite: Recommended Text: Notes: Lecture slides and Assignments 2 Course Objectives Design of Digital logic systems. Building large systems from small components (logic gates) EEG 481 Lec. 1 Introduction 3 Chapter 1 4 Course Outlines Number Systems (conversion and coding) Boolean Algebra Gate Level minimization Combinational Logic Design Synchronous sequential logic Registers and counters Memories and Programmable logic 5 What is the Meaning of Digital Logic Design? Digital means: 6 7 Why Digital? Digital systems are easier to design and implement than analog systems. EEG 481 Lec. 1 Introduction 8 9 Digital Logic circuit 10 11 12 13 NUMBER SYSTEMS – Representation A number with radix r is represented by a string of digits: An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m + 1 A- m in which 0 Ai < r and . is the radix point. The string of digits represents the power series: (Number)r = ( i=n-1 i=0 Ai r )+( (Integer Portion) j=-1 i j=-m + Aj r ) j (Fraction Portion) Number Systems – Examples Radix (Base) Digits 0 1 2 3 Powers of 4 Radix 5 -1 -2 -3 -4 General Decimal Binary Octal Hex. r 10 2 8 16 0 => r - 1 0 => 9 0 => 1 0 => 7 0 => F r0 r1 r2 r3 r4 r5 r -1 r -2 r -3 r -4 1 10 100 1000 10,000 100,000 0.1 0.01 0.001 0.0001 1 2 4 8 16 32 0.5 0.25 0.125 0.0625 1 8 64 512 4096 32768 0.125 0.015625 …. ….. 1 16 256 4096 65536 1048576 0.0625 0.00390625 …. …. Decimal Number System 16 Binary Number system EEG 481 Lec. 1 Introduction 17 Octal Number system 18 Hexadecimal Number System 19 Numbers with different bases The first 17 numbers in decimal, Binary, octal , and Hexadecimal 20 Data Types CONVERSION OF BASES Base R to Decimal Conversion (736.4)8 = 7 x 82 + 3 x 81 + 6 x 80 + 4 x 8-1 = 7 x 64 + 3 x 8 + 6 x 1 + 4/8 = (478.5)10 (110110)2 = ... = (54)10 (110.111)2 = ... = (6.785)10 (F3)16 = ... = (243)10 (0.325)6 = ... = (0.578703703 .................)10 Decimal to Base R number - Separate the number into its integer and fraction parts and convert each part separately. - Convert integer part into the base R number → successive divisions by R and accumulation of the remainders. - Convert fraction part into the base R number → successive multiplications by R and accumulation of integer digits Data Types EXAMPLE Convert 41.687510 to base 2. Integer = 41 41 20 1 10 0 5 0 2 1 1 0 0 1 (41)10 = (101001)2 Fraction = 0.6875 0.6875 x 2 1.3750 x 2 0.7500 x 2 1.5000 x 2 1.0000 (0.6875)10 = (0.1011)2 (41.6875)10 = (101001.1011)2 Exercise Convert (63)10 to base 5: Convert (1863)10 to base 8: Convert (0.63671875)10 to hexadecimal: (223)5 (3507)8 (0.A3)16 Decimal to Octal Conversion 23 Decimal to Hex. Conversion 24 Binary to Hex. Conversion 25 Binary to Octal Conversion 26 Signed Numbers 27 Complements COMPLEMENT OF NUMBERS Two types of complements for base R number system: - R's complement and (R-1)'s complement The (R-1)'s Complement Subtract each digit of a number from (R-1) Example - 9's complement of 83510 is 16410 - 1's complement of 10102 is 01012(bit by bit complement operation) The R's Complement Add 1 to the low-order digit of its (R-1)'s complement Example - 10's complement of 83510 is 16410 + 1 = 16510 - 2's complement of 10102 is 01012 + 1 = 01102 SIGNED NUMBERS Representation Need to be able to represent both positive and negative numbers - Following 3 representations Signed magnitude representation Signed 1's complement representation Signed 2's complement representation Example: Represent +9 and -9 in 7 bit-binary number Only one way to represent +9 ==> 0 001001 Three different ways to represent -9: In signed-magnitude: 1 001001 In signed-1's complement: 1 110110 In signed-2's complement: 1 110111 SIGNED NUMBERS Representation -Range of Signed 2’s complement : -2n-1 to 2n-1-1 -Range of Signed 1’s complement: -2n-1 +1 to 2n-1-1 -Range of Signed Magnitude: -2n-1 +1 to 2n-1-1 Decimal Signed-2’s complement Signed-1’s complement Signed Magnitude +7 +6 +5 +4 +3 +2 +1 +0 -0 -1 -2 -3 -4 -5 -6 -7 -8 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 - 0111 0110 0101 0100 0011 0010 0001 0000 1000 1001 1010 1011 1100 1101 1110 1111 - ARITHMETIC ADDITION: SIGNED MAGNITUDE [1] Compare their signs [2] If two signs are the same, ADD the two magnitudes - Look out for an overflow [3] If not the same , compare the relative magnitudes of the numbers and then SUBTRACT the smaller from the larger --> need a subtractor to add [4] Determine the sign of the result 6+9 6 0110 +) 9 1001 15 1111 -> 01111 6 + (- 9) 9 1001 -) 6 0110 - 3 0011 -> 10011 Overflow 9 + 9 or (-9) + (-9) 9 1001 +) 9 1001 overflow (1)0010 -6 + 9 9 1001 - ) 6 0110 3 0011 -> 00011 -6 + (-9) 6 0110 +) 9 1001 -15 1111 -> 11111 ARITHMETIC ADDITION: SIGNED 2’s COMPLEMENT Add the two numbers, including their sign bit, and discard any carry out of leftmost (sign) bit - Look out for an overflow Example 6 0 0110 +) 9 0 1001 15 0 1111 -6 +) 9 3 6 0 0110 +) -9 1 0111 -3 1 1101 -9 1 0111 1 0111 +) -9 -18 (1)0 1110 1 1010 0 1001 0 0011 (cn-1 cn) 9 +) 9 18 0 1001 0 1001 1 0010 overflow (cn-1 cn) Fixed Point Representations ARITHMETIC ADDITION: SIGNED 1’s COMPLEMENT Add the two numbers, including their sign bits. - If there is a carry out of the most significant (sign) bit, the result is incremented by 1 and the carry is discarded. Example +) +) +) 6 -9 -3 -9 -9 0 0110 1 0110 1 1100 1 0110 1 0110 (1)0 1100 1 0 1101 end-around carry -6 1 1001 0 1001 +) 9 (1) 0(1)0010 1 +) 3 0 0011 not overflow (cn-1 +) 9 0 1001 9 0 1001 1 (1)0010 overflow (cn-1 cn) cn) = 0 COMPARISON OF REPRESENTATIONS * Easiness of negative conversion S + M > 1’s Complement > 2’s Complement * Hardware - S+M: Needs an adder and a subtractor for Addition - 1’s and 2’s Complement: Need only an adder * Speed of Arithmetic 2’s Complement > 1’s Complement(end-around C) Fixed Point Representations ARITHMETIC SUBTRACTION Arithmetic Subtraction in 2’s complement Take the complement of the subtrahend (including the sign bit) and add it to the minuend including the sign bits. (A)-(-B) =(A)+ B (A)- B=(A)+( -B) Example : (-6) – (-13) = +7 in 8-bit representation 11111010 – 11110011 = 11111010 + 00001101 = 00000111 (+7) Binary codes Binary codes are used to represent discrete elements of information The codes must be in binary that the computer can only hold 0’s or 1’s. 36 Cont. Binary Codes Given n binary digits (called bits), there are 2n distinct elements that can be represented. But, you can represent m elements, m < Examples: 2n You can represent 4 elements with n = 2 bits: (00, 01, 10, 11). You can represent 4 elements with n = 4 digits: (0001, 0010, 0100, 1000). This second code is called a "one hot" code. Non-numeric Binary Codes Example: A binary code for the seven colors of the rainbow Code 100 is not used Color Red Orange Yellow Green Blue Indigo Violet Binary Code 000 001 010 011 101 110 111 External Representations DECIMAL CODES - Binary Codes for Decimal Digits Decimal BCD(8421) 0 1 2 3 4 5 6 7 8 9 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 2421 84-2-1 Excess-3 0000 0001 0010 0011 0100 1011 1100 1101 1110 1111 0000 0111 0110 0101 0100 1011 1010 1001 1000 1111 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 Note: 8,4,2,-2,1,-1 in this table is the weight associated with each bit position. d3 d2 d1 d0: symbol in the codes BCD: d3 x 8 + d2 x 4 + d1 x 2 + d0 x 1 8421 code. 2421: d3 x 2 + d2 x 4 + d1 x 2 + d0 x 1 84-2-1: d3 x 8 + d2 x 4 + d1 x (-2) + d0 x (-1) Excess-3: BCD + 3 Binary Coded Decimal (BCD) The BCD code is the 8,4,2,1 code. 8, 4, 2, and 1 are weights BCD is a weighted code This code is the simplest, most intuitive binary code for decimal digits and uses the same powers of 2 as a binary number, but only encodes the first ten values from 0 to 9. Chapter 1 40 Warning: Conversion or Coding? Do NOT mix up conversion of a decimal number to a binary number with coding a decimal number with a BINARY CODE. 1310 = 11012 (This is conversion) 13 0001|0011 (This is coding) BCD Addition BCD addition of two numbers involve following rules:1) Maximum value of the sum for two digits = 9 (max digit 1) + 9 (max digit 2) + 1 (previous addition carry) = 19 2) If sum of two BCD digits is less than or equal to 9 (1001) without carry then the result is a correct BCD number. 3) If sum of two BCD digits is greater than or equal to 10 (1010) the result is in-correct BCD number. Perform steps 4 for correct BCD sum. 4) Add 6 (0110) to the result. 42 Example -BCD addition Add 599 and 984 using BCD numbers 1 2 3 599 0101 1001 1001 +984 1001 1000 0100 1110 10001 1101 Binary Sum 1, 2 and 3 are greater than 1010. So, from Step 3 and 4 add ‘6’ to the sum. carry Result +6 1 1 1110 10001 1101 0110 0110 0110 1 0101 1000 0011 End Carry Answer. Result of BCD addition is 1583 Exercise: add 599 + 484 using BCD addition 43 GRAY CODE – Decimal ALPHANUMERIC CODES - ASCII Character Codes ASCII means “American Standard Code for Information Interchange” The ASCII code assigns binary patterns for - Numbers 0 to 9 - All the letters of English alphabet, uppercase and lowercase - Many control functions (E.g. BS = Backspace, CR = Carriage Return) and punctuation marks. The ASCII system uses 7 bits to represent each code 45 ASCII Code PARITY BIT Error-Detection Codes parity, an extra bit appended onto the code word to make the number of 1’s odd or even. A code word has even parity if the number of 1’s in the code word is even. A code word has odd parity if the number of 1’s in the code word is odd. 4-Bit Parity Code Example Even Parity Message - Parity 000 001 - 0 010 011 - 1 100 101 - 1 110 111 - 0 1 1 0 0 Odd Parity Message - Parity 000 001 010 011 100 101 110 111 - 1 0 0 1 0 1 1 0 The codeword "1111" has even parity and the codeword "1110" has odd parity. Both can be used to represent 3-bit data. PARITY BIT GENERATION Parity Bit Generation For b6b5... b0(7-bit information); even parity bit beven beven = b6 b5 ... b0 For odd parity bit bodd = beven 1 = beven Error Detecting codes PARITY GENERATOR AND PARITY CHECKER Parity Generator Circuit (even parity) b6 b5 b4 b3 b2 b1 beven b0 Parity Checker beven b6 b5 b4 b3 b2 b1 b0 Even Parity error indicator