Digital Logic Design Dr Waseem Ikram Lecture 03

  • Slides: 56
Download presentation
Digital Logic & Design Dr. Waseem Ikram Lecture 03

Digital Logic & Design Dr. Waseem Ikram Lecture 03

Recap n n Number System Conversion n Sum-of-Weights for converting to decimal n Repeated

Recap n n Number System Conversion n Sum-of-Weights for converting to decimal n Repeated division for converting from decimal Binary Arithmetic n Similar to Decimal Arithmetic n Multiplying by a constant by shifting left n Dividing by a constant by shifting right

Recap n Representing Numbers n Unsigned n Signed Magnitude n 2’s Complement

Recap n Representing Numbers n Unsigned n Signed Magnitude n 2’s Complement

2’s Complement form n n 1’s complement form 2’s complement form Binary number 01101

2’s Complement form n n 1’s complement form 2’s complement form Binary number 01101 1’s complement 10010 + 2’s complement 10011 (13) 1 (-13)

Addition and Subtraction with 2’s Complement 0101 0010 0111 +5 +2 +7 0101 1110

Addition and Subtraction with 2’s Complement 0101 0010 0111 +5 +2 +7 0101 1110 10011 +5 -2 +3 1011 1110 11001 -5 -2 -7 1011 0010 1101 -5 +2 -3

Addition and Subtraction 2’s complement vs. Signed 2’s Complement 0101 +5 0010 +2 0111

Addition and Subtraction 2’s complement vs. Signed 2’s Complement 0101 +5 0010 +2 0111 +7 1011 1110 11001 -5 -2 -7 Signed Binary 0101 0010 0111 +5 +2 +7 1101 1010 10111 -5 -2 -7

Addition and Subtraction 2’complement vs. Signed 0101 1110 10011 +5 -2 +3 0101 1010

Addition and Subtraction 2’complement vs. Signed 0101 1110 10011 +5 -2 +3 0101 1010 1111 +5 -2 +3 1011 -5 0010 +2 1101 -3 1101 0010 1111 -5 +2 -3

Range of Numbers n n n Unsigned n Positive Numbers Only (0 to 7)

Range of Numbers n n n Unsigned n Positive Numbers Only (0 to 7) n 3 -bit Signed Magnitude n Positive & Negative Numbers (-7 to 7) n 4 -bit 2’s Complement n Positive & Negative Numbers (-8 to 7) n 4 -bit

Range & Overflow n n 2 + 7 using 3 -bit unsigned binary? 9

Range & Overflow n n 2 + 7 using 3 -bit unsigned binary? 9 overflow? 2 – 7? Can not represent -7 in unsigned binary

Range and Overflow 1011 11000 -5 -3 -8 1011 1100 10111 -5 -4 -9

Range and Overflow 1011 11000 -5 -3 -8 1011 1100 10111 -5 -4 -9 0101 0100 1001 +9 +5 +4

Range of Binary Numbers n n n Processors can handle 64 -bit unsigned binary

Range of Binary Numbers n n n Processors can handle 64 -bit unsigned binary values. Maximum unsigned decimal number is 18. 446 x 1018 How to represent larger numbers? How to represent very small numbers? How to represent numbers with integer part and fraction part?

Floating Point Representation 38 n 32 -bit Floating Point Representation ANSI/IEEE Standard 754 defines

Floating Point Representation 38 n 32 -bit Floating Point Representation ANSI/IEEE Standard 754 defines 32 -bit Single-Precision Floating Point Sign Bit 1 Exponent Bits 8 Mantissa Bits 23 n 64 -bit Double-Precision Floating Point n n n

Floating Point Format n n n n 15 digit decimal number format Sign digit

Floating Point Format n n n n 15 digit decimal number format Sign digit 1 Exponent digits 2 Mantissa digits 12 6918. 3125 = 6. 9183125 x 103 Magnitude 69183125 Exponent 3

Floating Point Format n n n Normalized form 0. 69183125 x 104 Magnitude 69183125

Floating Point Format n n n Normalized form 0. 69183125 x 104 Magnitude 69183125 Exponent 4 + 0 4 6 9 1 8 3 1 2 n n 5 0 0 Max Number 0. 999, 999 x 1099 No negative exponent

Floating Point Format n n Option I n Increase exponent field to 3 digits

Floating Point Format n n Option I n Increase exponent field to 3 digits n 1099 to 10 -99 Option II n Biased 50 Exponent n add 50 1049 → 99 10 -50 → 0

Floating Point Format n +/- n Zero ? x x 0 0 0 0

Floating Point Format n +/- n Zero ? x x 0 0 0 0 Infinity (∞) ? 0 0 0

Floating Point Format n Allow 1048 → 98 Exponent 99 → ∞ n Exponent

Floating Point Format n Allow 1048 → 98 Exponent 99 → ∞ n Exponent 0 → 0 n n Decrease Bias to 49 1049 → 98 10 -48 → 1 n Exponent 99 → ∞ n Exponent 0 → 0 n 10 -49 → 1

Single-Precision F. P. format n n n n Representing 6918. 3125 = 1101100000110. 01012

Single-Precision F. P. format n n n n Representing 6918. 3125 = 1101100000110. 01012 Normalized form 1. 1011000001100101 x 212 S=0 E = 10001011 (127 + 12 = 139) M = 10, 110, 000, 011, 001, 010, 000 Hidden 1

Floating Point Numbers +1. 101 x 25 S=0 Exponent=10000100 Mantissa 101 0000 0000 -1.

Floating Point Numbers +1. 101 x 25 S=0 Exponent=10000100 Mantissa 101 0000 0000 -1. 01011 x 2 -126 S=1 Exponent=00000001 Mantissa 010 1100 0000 0 S=0 Exponent=0000 Mantissa 0000 0000 ∞ S=0 Exponent=1111 Mantissa 0000 0000

Hexadecimal Number System n n n Base 16 0, 1, 2, 3, 4, 5,

Hexadecimal Number System n n n Base 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Representing Binary in compact form n 11011000001102 = 1 B 06 H

Counting in Hexadecimal Decimal Binary Hexadecimal 0 0000 0 8 1000 8 1 0001

Counting in Hexadecimal Decimal Binary Hexadecimal 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 A 3 0011 3 11 1011 B 4 0100 4 12 1100 C 5 0101 5 13 1101 D 6 0110 6 14 1110 E 7 0111 7 15 1111 F

Counting in Hexadecimal Decimal Hexa. Decimal 16 10 24 18 32 20 17 11

Counting in Hexadecimal Decimal Hexa. Decimal 16 10 24 18 32 20 17 11 25 19 33 21 18 12 26 1 A 34 22 19 13 27 1 B 35 23 20 14 28 1 C 36 24 21 15 29 1 D 37 25 22 16 30 1 E 38 26 23 17 31 1 F 39 27

Binary-Hexadecimal Conversion n n Binary to Hexadecimal Conversion n 110101110010110 n 1101 0110 1011

Binary-Hexadecimal Conversion n n Binary to Hexadecimal Conversion n 110101110010110 n 1101 0110 1011 1001 0110 n. D 6 B 9 6 Hexadecimal to Binary Conversion FD 13 n 1111 1101 0011 n

Decimal-Hexadecimal Conversion n Decimal to Hexadecimal Conversion Indirect Method n Decimal →Binary → Hexadecimal

Decimal-Hexadecimal Conversion n Decimal to Hexadecimal Conversion Indirect Method n Decimal →Binary → Hexadecimal Repeated Division by 16

Decimal-Hexadecimal Conversion n Hexadecimal to Decimal Conversion Indirect Method n Hexadecimal →Binary → Decimal

Decimal-Hexadecimal Conversion n Hexadecimal to Decimal Conversion Indirect Method n Hexadecimal →Binary → Decimal Sum-of-Weights

Hexadecimal Addition & Subtraction n n Hexadecimal Addition n Carry generated Hexadecimal Subtraction n

Hexadecimal Addition & Subtraction n n Hexadecimal Addition n Carry generated Hexadecimal Subtraction n Borrow weight 16

Repeated Division by 16 Number Quotient Remainder 2096 131 0 131 8 3 8

Repeated Division by 16 Number Quotient Remainder 2096 131 0 131 8 3 8 0 8

Sum-of-Weights CA 02 (C x 163) + (A x 162) + (0 x 161)

Sum-of-Weights CA 02 (C x 163) + (A x 162) + (0 x 161) + (2 x 160) (12 x 163) + (10 x 162) + (0 x 161) + (2 x 160) (12 x 4096) + (10 x 256) + (0 x 16) + (2 x 1) 49152 + 2560 + 2 51714

Hexadecimal Addition Carry + 1 2 AC 6 92 B 5 BD 7 B

Hexadecimal Addition Carry + 1 2 AC 6 92 B 5 BD 7 B 6+5=11 d Bh C+B=23 d 17 h A+2+1=13 d Dh 2+9=11 d Bh

Hexadecimal Subtraction Borrow - 111 92 B 5 2 AC 6 67 EF 21

Hexadecimal Subtraction Borrow - 111 92 B 5 2 AC 6 67 EF 21 -6=15 d Fh 26 -C=14 d Eh 17 -A=7 d 7 h 8 -2=6 d 6 h

Octal Number System n n n Base 8 0, 1, 2, 3, 4, 5,

Octal Number System n n n Base 8 0, 1, 2, 3, 4, 5, 6, 7 Representing Binary in compact form n 11011000001102 = 154068

Counting in Octal Decimal 0 1 2 3 4 5 6 7 Binary 000

Counting in Octal Decimal 0 1 2 3 4 5 6 7 Binary 000 001 010 011 100 101 110 111 Octal 0 1 2 3 4 5 6 7

Counting in Octal Decimal Octal 8 10 16 20 9 11 17 21 Decimal

Counting in Octal Decimal Octal 8 10 16 20 9 11 17 21 Decimal Octal 24 30 25 31 10 11 12 13 14 15 26 27 28 29 30 31 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 32 33 34 35 36 37

Binary-Octal Conversion n n Binary to Octal Conversion n 110101110010110 n 011 010 101

Binary-Octal Conversion n n Binary to Octal Conversion n 110101110010110 n 011 010 101 110 010 110 n 3 2 6 5 6 2 6 Octal to Binary Conversion 1726 n 001 111 010 110 n

Decimal-Octal Conversion n Decimal to Octal Conversion Indirect Method n Decimal →Binary → Octal

Decimal-Octal Conversion n Decimal to Octal Conversion Indirect Method n Decimal →Binary → Octal Repeated Division by 8

Decimal-Octal Conversion n Octal to Decimal Conversion Indirect Method n Octal →Binary → Decimal

Decimal-Octal Conversion n Octal to Decimal Conversion Indirect Method n Octal →Binary → Decimal Sum-of-Weights

Octal Addition & Subtraction n n Octal Addition n Carry generated Octal Subtraction n

Octal Addition & Subtraction n n Octal Addition n Carry generated Octal Subtraction n Borrow weight 8

Repeated Division by 8 Number Quotient Remainder 2075 259 3 (O 0) 259 32

Repeated Division by 8 Number Quotient Remainder 2075 259 3 (O 0) 259 32 3 (O 1) 8 4 0 (O 2) 4 0 4 (O 3)

Sum-of-Weights 4033 (4 x 83) + (0 x 82) + (3 x 81) +

Sum-of-Weights 4033 (4 x 83) + (0 x 82) + (3 x 81) + (3 x 80) (4 x 512) + (0 x 64) + (3 x 8) + (3 x 1) 2048 + 0 + 24 + 3 2075

Octal Addition Carry 1 7602 + 5771 15573 2+1=3 d 3 O 0+7=7 d

Octal Addition Carry 1 7602 + 5771 15573 2+1=3 d 3 O 0+7=7 d 7 O 6+7=13 d 15 O 1+7+5=13 d 15 O

Octal Subtraction Borrow - 11 7602 5771 1611 2 -1=1 d 1 O 8

Octal Subtraction Borrow - 11 7602 5771 1611 2 -1=1 d 1 O 8 -7=1 d 1 O 13 -7=6 d 6 O 6 -5=1 d 1 O

Alternate Representations n n BCD Code n BCD Addition Gray Code

Alternate Representations n n BCD Code n BCD Addition Gray Code

Alternate Representations n BCD (Binary Coded Decimal) Code Decimal 0 1 2 3 4

Alternate Representations n BCD (Binary Coded Decimal) Code Decimal 0 1 2 3 4 BCD 0000 0001 0010 0011 0100 Decimal 5 6 7 8 9 BCD 0101 0110 0111 1000 1001

BCD Addition n n Multi-digit BCD numbers can be added together 23 0010 0011

BCD Addition n n Multi-digit BCD numbers can be added together 23 0010 0011 45 0100 0101 68 0110 1000 23 0010 0011 48 0100 1000 71 0110 1011 is illegal BCD number

BCD Addition n n Add a 0110 (6) to an invalid BCD number Carry

BCD Addition n n Add a 0110 (6) to an invalid BCD number Carry added to the most significant BCD digit 23 48 71 0010 0011 0100 1000 0110 1011 0110 0111 0001

Gray Code n n n Binary Code more than 1 bit change Electromechanical applications

Gray Code n n n Binary Code more than 1 bit change Electromechanical applications of digital systems restrict bit change to 1 n Shaft encoders n Braking Systems Un-Weighted Code

Gray Code Decimal 0 1 2 3 4 5 6 7 Gray 0000 0001

Gray Code Decimal 0 1 2 3 4 5 6 7 Gray 0000 0001 0010 0111 0100 Binary 0000 0001 0010 0011 0100 0101 0110 0111

Gray Code Application

Gray Code Application

Alphanumeric Code n n n n Numbers, Characters, Symbols ASCII 7 -bit Code American

Alphanumeric Code n n n n Numbers, Characters, Symbols ASCII 7 -bit Code American Standard Code for Information Interchange 10 Numbers (0 -9) 26 Lower Case Characters (a-z) 26 Upper Case Characters (A-Z) Punctuation and Symbols 32 Control Characters

ASCII Code n n n n Numbers 0 to 9 ASCII 0110000 (30 h)

ASCII Code n n n n Numbers 0 to 9 ASCII 0110000 (30 h) to 0111001 (39 h) Alphabets a to z ASCII 1100001 (61 h) to 1111010 (7 Ah) Alphabets A to Z ASCII 1000001 (41 h) to 1011010 (5 Ah) Control Characters ASCII 0000000 (0 h) to 0011111 (1 Fh)

Alphanumeric Code n n n Extended ASCII 8 -bit Code Additional 128 Graphic characters

Alphanumeric Code n n n Extended ASCII 8 -bit Code Additional 128 Graphic characters Unicode 16 -bit Code

Error Detection n Digital Systems are very Reliable Errors during storage or transmission Parity

Error Detection n Digital Systems are very Reliable Errors during storage or transmission Parity Bit n Even Parity n Odd Parity

Odd Parity Error Detection n n n n Original data 10011010 With Odd Parity

Odd Parity Error Detection n n n n Original data 10011010 With Odd Parity 110011010 1 -bit error 11010 Number of 1 s even indicates 1 -bit error 2 -bit error 110110010 Number of 1 s odd no error indicated 3 -bit error 10010 Number of 1 s even indicates error

Summary n n n 2’s Complement Range and Overflow Floating Point representation

Summary n n n 2’s Complement Range and Overflow Floating Point representation

Summary n n Hexadecimal Number System n Binary-Hexadecimal Conversion n Decimal-Hexadecimal Conversion Octal Number

Summary n n Hexadecimal Number System n Binary-Hexadecimal Conversion n Decimal-Hexadecimal Conversion Octal Number System n Binary-Octal Conversion n Decimal-Octal Conversion

Summary n n Alternate Representations n BCD Code n Gray Code Alphanumeric Codes n

Summary n n Alternate Representations n BCD Code n Gray Code Alphanumeric Codes n n ASCII Error Detection n Parity Bit