Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEL 3705 / 3705L Digital Logic Design

Similar presentations


Presentation on theme: "EEL 3705 / 3705L Digital Logic Design"— Presentation transcript:

1 EEL 3705 / 3705L Digital Logic Design
Fall 2006 Instructor: Dr. Michael Frank Lecture Module #5: Radix Number Systems & Arithmetic 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

2 Topics for Today (Fri. 1/19)
Administrative announcements: Example of a design document handed out Textbook due date pushed back to next Tue. Lab #2 pushed back a week – Next week’s labs are to catch up & get started Topic: Arbitrary-radix (base-b) number systems Base-b number representations Commonly used bases in digital logic: 2, 8, 16 Arithmetic in base-b number systems Conversion between different bases 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

3 Basic logic gates: NOT, OR, AND, XOR
Logic Review / Preview Basic logic gates: NOT, OR, AND, XOR 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

4 Why Bits (Binary Digits)?
As we’ll learn, computers represent all information using bits. A bit means a binary (i.e., base 2) digit, 0 or 1. This is done for several reasons: Two states (digit values) is all that is really needed. Any desired information can be represented using sequences of bits. Encoding information using 2-state systems offers the best noise immunity for a given energy/information ratio. Computers based on bits tend to be the most energy-efficient. A bit conveniently can represent the truth value of any given proposition in Boolean logic. That is, “true” (1) or “false” (0). Bits can be simply and easily manipulated by simple hardware elements called “logic gates.” These implementing the basic operators of Boolean logic. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

5 M. Frank, EEL3705 Digital Logic, Fall 2006
Boolean Logic: Review For reasoning about whether propositions (statements) are true (T) or false (F). The truth value of the proposition. The important functional operators of Boolean logic include: NOT(x) = {T iff x=F (otherwise F)} AND(x,y) = {T iff both x=T and y=T} OR(x,y) = {T iff either x=T or y=T, or both} XOR(x,y) = {T iff either x=T or y=T, but not both} George Boole iff = “if and only if”  “exclusive OR” 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

6 Boolean Logic Notations
You should be aware that any given expression of Boolean logic could be written in several styles: Writing operators as functions: XOR(OR(AND(a,b),NOT(c)),d) Using operator names “infix” (between their operands): ((a AND b) OR (NOT c)) XOR d Using mathematical logic operator symbols: [(a  b)  ¬c]  d Using C programming language operators: ((a & b) | ~c) ^ d Using Boolean algebra notation: Preferred in this course 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

7 M. Frank, EEL3705 Digital Logic, Fall 2006
Logic Gate Icons Inverter Logical NOT, Boolean complement AND gate Boolean product OR gate Boolean sum XOR gate exclusive-OR, sum mod 2 x x x·y y x x+y y x xy y 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

8 M. Frank, EEL3705 Digital Logic, Fall 2006
Multi-input AND, OR, XOR Can extend these gates to arbitrarily many inputs. Two commonly seen drawing styles: Note that the second style keeps the gate icon relatively small. x1 x1x2x3 x2 x3 x1 ⋮ x5 x1…x5 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

9 M. Frank, EEL3705 Digital Logic, Fall 2006
NAND, NOR, XNOR Just like the earlier icons, but with a small circle on the gate’s output. Denotes that the output is complemented. Circles could also be placed on inputs. Means, input is complemented before being used. x y x y x y 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

10 CMOS NAND gate implementation
A NAND gate is particularly easy to implement in CMOS: Simple 4-transistor circuit  A NOR gate is equally simple, but slower, due to series pFETs If we wanted to, we could build any computer using nothing but NAND gates and wires! Vdd x y xy Vss = GND 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

11 Base-b Number Systems (with emphasis on bases 2, 8, 16)
Topic #1 Base-b Number Systems (with emphasis on bases 2, 8, 16) 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

12 M. Frank, EEL3705 Digital Logic, Fall 2006
1. Base-b Number Systems List of subtopics: 1.1. Integers in base-b number systems 1.2. Arithmetic in alternative bases 1.3. Methods for converting between different bases 1.4. Fixed-width binary arithmetic and overflow 1.5. Signed number representations & overflow 1.6. Fixed-point representation of fractional numbers 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

13 M. Frank, EEL3705 Digital Logic, Fall 2006
Base-b Number Systems Our ordinary decimal (base ten) number system can be used to represent any number while using only ten different digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 But, there’s nothing special about the number ten! We only use base ten because we have ten fingers! Given any integer b > 1, we can describe an alternative base b (or radix b) number system, in which: There are exactly b different digit symbols The values of the digits are 0, 1, …, b1 An arbitrary integer N > 0 can be written uniquely as a sequence of k digits like (dk1dk2…d2d1d0)b, where 0 ≤ di < b and the first digit dk1 > 0. This is called the base b expansion of N. The value of N is given by the expression: 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

14 Alternate Bases Most Widely Used in Computer Engineering
Base 2 (binary): The only digit values are 0 and 1 Used internally in all modern computers Base 8 (octal): Digits are 0, 1, 2, 3, 4, 5, 6, 7 Each octal digit represents a sequence of 3 bits Base 16 (hexadecimal or just “hex”): Digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Where A=ten, B=eleven, …, F=fifteen. Each hex digit represents a sequence of 4 bits 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

15 Four Representations of The First Sixteen Non-negative Integers
Base (Radix) Ten Two Eight Sixteen 1 2 10 3 11 4 100 5 101 6 110 7 111 Base (Radix) Ten Two Eight Sixteen 8 1000 10 9 1001 11 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

16 Arithmetic in Alternative Bases
Subtopic #1.2 Arithmetic in Alternative Bases 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

17 Arithmetic in Alternative Bases
Procedures for doing arithmetic in any arbitrary base are essentially identical to those you already know for doing arithmetic in base ten… Only the number of digit values is different! This affects the basic addition/multiplication tables, but not much else… 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

18 Binary Addition/Multiplication Tables
Note that here, “+” means ordinary addition, not logical OR. + 1 102 × 1 Note: Read this digit sequence as “one-zero” or “one-zero base two” or “binary 2” Don’t call this a “ten!” The English word ten refers to the number In binary, that number is written 1010. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

19 Topics for Today (Mon. 9/11)
Administrivia: HW#1 is posted. Topic #1: Base-b number systems (cont.) Finish arithmetic in base-b number systems Conversion between different bases Fixed-width and signed arithmetic and overflows And, time permitting: Demonstration of the design & programming of a simple circuit to display the word “HI.” on the MAX 7000’s 7-segment LED display. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

20 Binary Addition Example
Here we will use the facts that 1+1 = 2 = 102 and = 3 = 112. Check work in decimal: 1 1 1 Carry bits = = 1310 = = 710 1 1 02 = = 2010 = 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

21 Binary Subtraction Example
Here we use the fact that 102  1 = 2  1 = 1. 1 1 13  7 1 1 02 6 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

22 Binary Multiplication Example
Very easy, since all rows are either ×0 or ×1: × 13 5 Partial Products 65 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

23 Binary Division Example
Subtract the divisor at each position, if possible… 1 1 Quotient 1 0 Divisor Dividend − 1 0 1 0 − 1 0 Check: 13/2 = 6 r 1  0 1 − 0 1 Remainder 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

24 Octal Addition/Multiplication Tables
+ 1 2 3 4 5 6 7 10 11 12 13 14 15 16 × 1 2 3 4 5 6 7 10 12 14 16 11 17 22 25 20 24 30 34 31 36 43 44 52 61 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

25 Hexadecimal Addition Table
+ 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

26 Hexadecimal Multiplication Table
+ 1 2 3 4 5 6 7 8 9 A B C D E F 10 12 14 16 18 1A 1C 1E Exercise for the student: Figure out and fill in the rest of this table! 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

27 Hexadecimal Arithmetic Examples
Hex addition and multiplication: 1 3E42 × D86 3E42 + D86 1758C 4 B C 8 1F210 + 3295A 349F08C 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

28 Base Powers to Memorize
For base conversion and checking of results, as well as many other purposes, you should try to memorize the following: Powers of 2 up to at least 216: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 Powers of 8 up to at least 85: 1, 8, 64, 512, 4096, 32768 Powers of 16 up to 168: 1; 16; 256; 4,096; 65,536; 1,048,576; 16,777,216; 268,435,456; 4,294,967,296 One “K” (kibi) One “Meg” (mebi) Four “Gigs” (gibis) 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

29 Base Conversion Methods
Subtopic #1.3 Base Conversion Methods 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

30 M. Frank, EEL3705 Digital Logic, Fall 2006
Base Conversions Some procedures for converting a number N from an old base b to a new base B: Method 0: If one of the bases is a power of the other, can do direct substitution of (groups of) digits. E.g., octal ↔ binary ↔ hex conversions work like this Otherwise: Two methods for conversion using arithmetic in the new base B: Method 1: Directly evaluate the polynomial expression for Nb. Method 2: (Horner’s rule) Repeatedly multiply by b and add digits of N, reading from left to right. Two methods for conversion using arithmetic in the old base b: Method 3: Repeatedly divide N by B, the remainders are the new digits, reading from right to left. Method 4: Repeatedly divide N by the largest power of B less than N; the quotients are the new digits, reading from left to right. Natural if new base is 10 Natural if old base is 10 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

31 M. Frank, EEL3705 Digital Logic, Fall 2006
Example of Method 0 Convert 3F616 to octal. We’ll first convert to binary, then binaryoctal. Hex to binary groups of 4 bits: 3  00112, F  11112, 6  The complete binary representation is: Binary groups of 3 bits to octal: 1  1, 111  7, 110  6, 110  6 The complete octal representation is: 17668 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

32 M. Frank, EEL3705 Digital Logic, Fall 2006
Examples of Method 1 Convert to base 10. = (taking the sum from right to left) = 1×20 + 1×21 + 0×22 + 1×23 + 0×24 + 1× ×26 + 0×27 + 1×28 = 1·1 + 1·2 + 0·4 + 1·8 + 0·16 + 1·32 + 1· · ·256 = = Convert 3D9616 to base 10. 3D9616 = 3× × × ×160 = 3×4, × ×16 + 6×1 = 12, , = 15,76610 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

33 M. Frank, EEL3705 Digital Logic, Fall 2006
Examples of Method 2 Convert to base 10. 1×2 + 0 = 2, ×2 + 1 = 5, ×2 + 1 = 11, ×2 + 0 = 22, ×2 + 1 = 45, ×2 + 0 = 90, ×2 + 1 = 181, ×2 + 1 = Convert 3D9616 to base 10. 3×16 = 48; +13 = 61; ×16 = 976; +9 = 985; ×16 = 15,760; +6 = 15,76610. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

34 Example of Method 3 (Dec.  Binary)
Convert to binary. 363 ÷ 2 = 181 r ÷ 2 = 90 r 1 90 ÷ 2 = 45 r 0 45 ÷ 2 = 22 r 1 22 ÷ 2 = 11 r 0 11 ÷ 2 = 5 r 1 5 ÷ 2 = 2 r 1 2 ÷ 2 = 1 r 0 1 ÷ 2 = 0 r 1. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

35 Method 3 Variation: Tower Drawing Style
Same algorithm, but without rewriting of quotients: 0 r 1 2 1 r 0 2 2 r 1 2 5 r 1 2 11 r 0 2 22 r 1 2 45 r 0 2 90 r 1 2 181 r 1 2 363 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

36 Example of Method 3 (Dec.  Hex)
Convert 15,76610 to hexadecimal. 15,766 ÷ 16 = 985 r 6; 985 ÷ 16 = 61 r 9; 61 ÷ 16 = 3 r 13; 3 ÷ 16 = 0 r 3. 3D9616 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

37 Example of Method 4 (Dec.  Binary)
Convert to binary. 363 ÷ 256 = 1 r ÷ 128 = 0 r ÷ 64 = 1 r ÷ 32 = 1 r ÷ 16 = 0 r ÷ 8 = 1 r 3 3 ÷ 4 = 0 r 3 3 ÷ 2 = 1 r 1 1 ÷ 1 = 1 r 0 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

38 M. Frank, EEL3705 Digital Logic, Fall 2006
Method 4 Variation When converting from binary, the divides in method 4 can be replaced by simple subtraction of the powers of 2. Example: Convert to binary. 363  256 = 107 107  64 = 43 43  32 = 11 11  8 = 3 3  2 = 1 1  1 = 0 256 128 64 32 16 8 4 2 1 1 1 1 1 1 1 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

39 Example Where Neither Base is 10 or a Power of the Other
Convert 2103  ___5 using each of methods 1-4. Method 1: N = 2·32 + 1·31 + 0·30 = 2· ·3 + 0 2·145 = 2· ·4 = = 335 N = = = 415. Method 2: 2 · 3 = 115, + 1 = 125, · 3 = = 415. Method 3: 2103 / 123 = 113 r 1, 113 / 123 = 0 r 113  415 Method 4: 2103 / 123 = 113 r 1, 1 / 1 = 1 r 0  415 Doing addition and multiplication in base 5 Doing division in base 3 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

40 M. Frank, EEL3705 Digital Logic, Fall 2006
Another Way (Method 5) When converting between two bases neither of which is base 10 or a power of the other, you might find the following strategy easier than using any of methods 1-4 directly: First, convert from the old base to base 10 using either method 1 or 2 Next, convert from base 10 to the new base using either method 3 or 4. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

41 M. Frank, EEL3705 Digital Logic, Fall 2006
Example of Method 5 Convert 2103  ___5 using method 5. First use method 1 to convert to base 10: 2103 = 2·32 + 1·31 + 0·30 = 2· =18+3= 2110 Next use method 4 to convert to base 5: 2110 ÷ 5 = 4 r 1  415 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

42 Topics for Today (Fri. 9/15)
Administrivia: HW#1 is due Monday. Topic #1: Base-b number systems (finish) Fixed-width and signed arithmetic and overflows Fixed-point and floating-point binary fractions Topic #2, Miscellaneous Codes BCD, ASCII, Parity codes, Gray codes, Hamming codes And, time permitting: Demonstration of the design & programming of a simple circuit to display the word “HI.” on the MAX 7000’s 7-segment LED display. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

43 Fixed-Width Binary Arithmetic and Overflow
Subtopic #1.4 Fixed-Width Binary Arithmetic and Overflow 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

44 Fixed-Width Binary Arithmetic
In digital systems, usually there is only a fixed number n of bits of storage immediately available to represent a given arithmetic result. What happens if the numeric value of the desired result doesn’t fit in the given number of bits? The usual behavior of hardware is just to truncate the result, in other words to discard some of the extra bits, usually on the left… This is equivalent to using “modulo 2n” arithmetic. We should be aware of when this procedure will lead to a different numeric result than regular arithmetic. In other words, we should know the overflow conditions. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

45 Modulo-m arithmetic In modulo-m arithmetic, all numeric results are projected onto a value in the range [0,m). Namely, the remainder when dividing by m. Example: 4+3 = 7 ≡ 2 (mod 5) Since 7/5 = 1 r 2. We can visualize the ordinary number line as laid out along a spiral straddling lines representing the different possible mod-m values. ≡ 0 (mod 5) 20 15 ≡ 1 (mod 5) 10 ≡ 4 (mod 5) 19 5 21 14 16 9 11 4 6 1 3 2 8 7 13 12 18 17 22 ≡ 2 (mod 5) ≡ 3 (mod 5) Visualization of number line in modulo-5 arithmetic 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

46 Modulo 2n arithmetic Fixed-width binary arithmetic with n bits is equivalent to modulo 2n arithmetic. Discarding the leftmost bits projects us onto one of the arms of the spiral. An “overflow” happens when we wrap around and leave the innermost arm of the spiral. Crossing the dotted red line… It’s like how your car odometer rolls over after 100,000 miles. 00 100 00 11 111 11 01 101 01 10 110 10 2-bit truncation spiral 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

47 M. Frank, EEL3705 Digital Logic, Fall 2006
Number Wheel Diagrams We can represent modulo arithmetic using a “number wheel” picture Think of this as similar to a roulette wheel, or the face of a clock As you wrap around past the overflow marker, you start repeating the same numbers over again. overflow marker 1 7 000 111 001 6 2 110 010 101 011 5 3 100 4 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

48 Unsigned Overflow Example
Suppose we are doing fixed-width, unsigned binary arithmetic in three bits, and we add the numbers 5 and 3. What is the result, and is there an overflow? Expressed in 3 bits, 5 = 1012, 3 = 0112. Carry out the addition shown at right. The result is = 8, which does not fit in 3 bits. The leftmost 1 gets truncated away, leaving 000 as the result. So yes, there is an overflow! Addition causes an overflow whenever there is a carry out of the highest-order bit position. 1 1 1 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

49 M. Frank, EEL3705 Digital Logic, Fall 2006
Subtopic #1.5 Signed Number Representations, Signed Arithmetic, & Signed Overflow Conditions 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

50 Signed Number Representations
In digital systems, we often need to represent signed (positive or negative) numbers. On paper, a signed base-b number can of course be denoted by just writing down a + or  sign in front of it. But, how are signed numbers to be coded using bits? There are many possible methods. We’ll discuss: Sign-magnitude representations Biased representations One’s-complement representations Two’s-complement representations This is the one that is most commonly used today in digital systems, due to the simplicity of its implementation 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

51 Sign-Magnitude Representation
To represent signed numbers in the range [2n + 1, 2n  1], we can use one bit for the sign and n bits for the unsigned magnitude (absolute value) of the number. Most common convention for meaning of sign bit: 0 = positive, 1 = negative. Usually, sign bit is written before the magnitude I.e., next to the most significant bit of the magnitude. Example: A four-bit sign-magnitude representation of 6 is shown at right Note that in this system, there are different codes for +0 and 0, even though their values are mathematically the same! Coping with this makes the design of arithmetic circuits more complicated. Sign = neg. Magni- tude = 6 1110 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

52 Wheel Diagrams of Unsigned vs. Sign-Magnitude Numbers
Sign-magnitude has more discontinuities, as well as some redundancy and inconsistent ordering… overflow marker increasing order increasing order 3 1 1 000 7 000 111 001 111 001 2 zero codes redundant 2 6 2 110 010 110 010 increasing order 101 011 101 011 3 5 3 1 100 100 0 4 Four-bit Unsigned Four-bit Sign-Magnitude 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

53 Biased Representations
In a biased or shifted signed number representation, we represent integers in the range [n, p] by using unsigned numbers in the range [0, n+p]. To convert signed to unsigned: Add n. To convert unsigned to signed: Subtract n. When adding biased numbers, we must subtract the bias. To avoid double-counting it! Example: Can represent numbers in the range [8, 7] using the number range [0, 15] by adding 8 to every number. Numbers in [0, 15] can be represented using 4 bits. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

54 Wheel Diagrams of Unsigned and Biased Signed Numbers
No extra discontinuities, consistent ordering… However, arithmetic must still correct for the bias 4 3 1 3 7 000 000 111 001 111 001 2 2 6 2 110 010 110 010 increasing order increasing order 101 011 101 011 1 1 5 3 100 100 4 Four-bit Unsigned Four-bit bias-4 signed 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

55 One’s-Complement Representation
To obtain the representation of x, flip or invert all the bits in the representation of x. I.e., change all 1’s to 0’s, and 0’s to 1’s. Like sign-magnitude, encodes the range [2n + 1, +2n  1] in n+1 bits, uses the high-order bit as the sign bit, and has redundant codes for 0. Unlike sign-magnitude, there is only one discontinuity (instead of 2) when going around the number wheel… However, the extra 0 code still requires corrections. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

56 Wheel Diagrams of Unsigned and One’s-Complement Numbers
Discontinuity is only moved, and order is consistent, but there are redundant zero codes: 0 1 1 7 000 000 111 001 111 001 1 increasing order 2 6 2 110 010 110 010 increasing order 101 011 101 011 3 5 3 2 100 100 Note if we could shift all of these numbers up by one code, we could get rid of the −0 3 4 Four-bit Unsigned Four-bit One’s-Complement 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

57 Two’s-Complement Representation
Represent x as One’s-complement, plus another 1 Thus the name “two’s complement.” The first bit is still the sign bit… Or, you can also think of it as a negative digit, representing the “2n1’s” position in the number. E.g., the high bit in a 4-bit number is the 8’s position (instead of the 8’s position). Big advantage of two’s complement: The addition circuit is the same as for unsigned! 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

58 Wheel Diagrams of Unsigned and Two’s-Complement Numbers
Only one discontinuity, no redundant codes! No need to correct for biases! 1 1 1 000 7 000 111 001 111 001 2 2 6 2 110 increasing order 010 110 010 increasing order 011 101 011 101 3 3 5 3 100 100 4 4 Four-bit Unsigned Four-bit Two’s-Complement 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

59 Overflow Conditions for Two’s Complement
Overflow occurs when we cross the boundary separating the most positive number, 01111… from the most negative number, 10000… When this happens, there is a carry from the second-most-significant bit position (bit #n2) to the most significant bit position (bit #n1). Doing this by itself is incorrect, since the most significant bit position has the opposite sign. However, if there is also a carry out of the most significant bit position, then it’s OK… In this case, we’re just going through the continuous range from the negative numbers close to zero, 111…1 to the positive numbers close to zero, 000…0. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

60 Signed Overflow Example
Is there an overflow when adding the bit patterns 110 and 011 in three-bit, signed two’s-complement arithmetic? Method 1: Does sum fit in range? 110  2, 011  3, 2+3 = +1  Yes; no overflow. Method 2: Perform unsigned add. Carries into and out of high bit position are the same  no signed overflow. 1 1 1001 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

61 Subtraction in Two’s Complement
To perform the subtraction x  y in n bits using two’s complement arithmetic, Just compute z, the two’s complement of y, using z = y = y + 1. Or, shortcut method: Flip all bits that are to the left of the rightmost 1. Then, simply add x + z, and truncate the result to n bits. If there is no signed overflow, the result will be correct. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

62 Two’s-Complement Subtraction Example
Compute the subtraction 13 using two’s complement arithmetic in three bits. 1 = 0012 3 = 0112 3 = 1002 (one’s complement) 3 = 3+1 = 1012 (two’s complement) 1  3 = 1 + (3) = = 1102 Bits in and out of high bit match; no signed overflow 1102 = 4 + 2 = 2 (correct result) 1 110 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

63 Two’s Complement Subtraction: Another Practice Problem
Perform this subtraction: –3 – (–6) in 4-bit two’s complement (is there an overflow?) +3 = 0011, ~3 = 1100, ~3+1 = 1101 = -3 +6 = 0110, ~6 = 1001, ~6+1 = 1010 = -6 -6 = 1010, ~(-6) = 0101, ~(-6)+1 = 0110 = +6 -3 = = 1| > +3 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

64 M. Frank, EEL3705 Digital Logic, Fall 2006
Radix Complement A generalization of two’s complement to bases other than 2. In any base b, the radix complement [N]b of an n-digit number Nb is defined as [N]b = bn − Nb. The normal unsigned representation of [N]b is then the signed representation of −Nb. Radix complement is the same as two’s complement when b=2. Example: −00012 → [0001]2 = 24 − 1 = − 1 = You’ll rarely encounter this concept for b2. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

65 Radix Complement Example for b2
Compute the three’s complement of the number (= 1710). The number of digits in is n=4. [0122]3 = 34 − 1223 = 8110 − 1710 = 6410 = We could obtain the same result by the idea of “complementing the digits and adding 1” where digit complements are pairs of digit values that sum to the max digit value, here b−1 = 2. In base 3, 0 and 2 are digit complements, and 1 is its own digit complement. [0122]3 = ~ = = The two methods are equivalent in any base b, because ((b−1)(b−1)…(b−1))b + 1 = 100…0b = bn. n n 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

66 Diminished Radix Complement
This is just the radix complement minus 1. In the book’s notation, [N]b−1 = [N]b − 1. This is the same as just taking the digit complement of all digits. where, in base b, the digit complement of any digit d is given by ~d = (b−1)−d. In base b=2, the digit complement of a digit d is given by 1−d, which is another reason that we call the digit complement in base 2 the “one’s complement”. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

67 Fixed-Point and Floating-Point Binary Fractional Numbers
Subtopic #1.6 Fixed-Point and Floating-Point Binary Fractional Numbers 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

68 Radix Fractions In decimal, we write digits after the decimal point to denote coefficients of negative powers of 10. Example: means: 3× ×10−1 + 4×10−2 + 1×10−3 + 5×10−4 + 9×10−5 By the same token, in any base b, digits after the “radix point” denote coefficients of negative powers of b. General form: dk−1dk−2…d2d1d0.d−1d−2d−3…d−j+1d−j k digits before the radix point j digits after the radix point 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

69 Fixed-Point Binary Fractions
In a fixed-width, fixed-point binary representation of a fractional number, the “binary point” is always implicitly at some predefined location (independent of the data) E.g., suppose it is defined to be in between the first 5 and last 3 bits of an 8-bit word… Then k=5, j=3… The value of the bit pattern shown is then: ½ + 1/8 = 4 3 2 1 −1 −2 −3 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

70 Fixed-Point Binary Arithmetic
Analogous to arithmetic with ordinary decimal fractions. Just like binary integer arithmetic, except that you must align the binary points, and ensure that the radix point of the result is positioned as expected, and round as needed. Example: In k=2,j=2 fixed point, multiply × 1011 × 0101 round to: = 3.510 Decimal equivalent: 2.75 × round to nearest 0.25 3.5 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

71 Fixed-Point Two’s Complement
Can represent signed fractional numbers using fixed-point two’s complement representation. Just as with integers, the bit in the most significant position (position k−1) represents the coefficient of the highest power of two, 2k−1, except that its value is negative. Arithmetic procedures and overflow conditions are essentially the same as with integer two’s complement. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

72 Floating-Point Numbers
Similar to scientific notation, but not based on the radix 10… The radix that is standardly used in digital floating-point representations is 2 Advantages include: Precisely handles a wider range of numeric magnitudes. General mathematical form: ±N = ±M × rE M, the mantissa, is a fixed-point number, usually normalized to [0,1). r, the radix, is an implicitly agreed upon constant. E, the exponent, is a signed integer (usu. in biased representation). The fixed point number (dk−1…d0.d−1…d−j)r gets represented in normalized FP as (.dk−1…d0d−1…d−j)×rk. Mantissa signs are usually represented in sign-magnitude form The leading 1 of normalized binary mantissas can be left implicit 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

73 Simple Floating-Point Example
Represent the number − as a 10-bit floating-point binary number composed of a sign bit, a 4-bit exponent with a bias of 8, and a 5-bit mantissa with an implicit leading 1. − = − = −.1101×22 Mantissa bits: (leading 1 is implicit) Biased exponent = 2+8 = 1010 = Complete representation: sign exp mantissa 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

74 M. Frank, EEL3705 Digital Logic, Fall 2006
Topic #2 Miscellaneous Codes 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

75 M. Frank, EEL3705 Digital Logic, Fall 2006
Miscellaneous Codes Besides the basic representations you’ve already learned for unsigned and signed integers and fractions, many other binary codes also exist for representing numbers, as well as letters, and all manner of other things (colors, machine instructions, etc.) other types of codes are used to protect data from damage or eavesdropping In this section we’ll cover a few of the most commonly encountered codes: BCD, ASCII, Parity codes, Gray codes We’ll also introduce some general concepts of error control codes. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

76 Special Binary Word Sizes
In computer engineering, digital telecommunications engineering, and computer science, certain special numbers of bits that have names commonly associated with them: 3 bits – An octal digit. 4 bits (1 hex digit) – A nibble (or nybble?). 8 bits (2 hex digits) – A byte (B), character, or octet. 16 bits (4 hex digits) – A half-word or a short int. 32 bits (8 hex digits) – A word or an int. 64 bits (16 hex digits) – A double-word or long int. 128 bits (32 hex digits) – A quad-word or long long int. 8,192 bits (2,048 hex digits) – A kilobyte (kB) or kibibyte (kiB). And so forth, with 1,024 kiB = 1 MiB, and 1,024 MiB = 1 GiB, etc. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

77 M. Frank, EEL3705 Digital Logic, Fall 2006
Binary-Coded Decimal A way of representing decimal numbers directly in binary. The digits 0-9 are represented with their 4-bit equivalents (same as hex digits 0-9). However, codes remain unused. The values of the digit positions are taken as powers of 10, rather than 16. Example: = 0011,0101,1000 in BCD. BCD is more human-readable than hex or binary, but arithmetic hardware for plain binary is simpler 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

78 The ASCII Character Code American Standard Code for Information Interchange
Standards ANSI INCITS (R2002), ANSI X (R1997), ISO Control code glyphs; normally not printed. From ANSI X , ISO Meanings of control codes are defined at: ~jkorpela/chars/ c0.html optional 8th bit may be 0 or used for parity or for code extensions 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

79 Symbols I’ll Use for the Non-Printing ASCII Control Characters
You can insert any of these special symbols into MS Word documents using the Insert Symbol menu command and a Unicode font such as Arial Unicode MS. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

80 M. Frank, EEL3705 Digital Logic, Fall 2006
ASCII Code Example Represent the string “Hello, World!” in ASCII code as a sequence of hexadecimal digits. Use the unit separator (∫) control character to delimit the end of the string. Or, written out as a single enormous number, this is: 4865,6c6c,6f2c,2057,6f72,6c64,211F16. Writing commas between every 4 hex digits for readability. H e l o , W r d ! 48 65 6c 6f 2c 20 57 72 64 21 1F 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

81 M. Frank, EEL3705 Digital Logic, Fall 2006
Parity Codes Used for error detection. After n bits, b0…bn−1, add one more bit bn defined to be the XOR (or NXOR) of the others: With XOR, bn = b0b1…bn−2bn−1. Using NXOR, bn = ~(b0b1…bn−2bn−1). The extra bit bn is called a parity bit. If XOR is used, we say the code is even parity, because b0+b1+…+bn ≡ 0 (mod 2); the sum of all bits is an even number. if NXOR is used, the code is called odd parity. because b0+b1+…+bn ≡ 1 (mod 2); the sum of all bits is an odd number. When all n bits are received, if bn does not match the remaining bits according to how it was generated, then we know that at least one of the bits was altered in transmission. Any single bit error can be detected using this technique. More sophisticated variants can also be used to locate and correct bit errors. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

82 M. Frank, EEL3705 Digital Logic, Fall 2006
Distance Metrics A common distance metric between two binary words I,J of the same length n is the number of bits that differ between them. This gives the number of single-bit errors that would have to occur to transform I into J. The more distant the codewords in a code are from each other, the more resilient the code is to independent errors. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

83 M. Frank, EEL3705 Digital Logic, Fall 2006
Distance Example The distance between any two given 3-bit strings is the same as the number of edges of the 3-cube at right that must be traversed to get from one to the other. E.g., d(001,110) = 3. 011 111 001 101 010 110 000 100 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

84 General Requirements for Error Correction and Detection
Let dmin be the minimum distance between the codewords in a code C. Then the code C can correct any set of up to t bit errors and at least detect up to s additional errors, for any pair (s,t) where 2t + s < dmin . 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

85 Example of Distance Metric and Error Correction/Detection
Consider a 3-bit code with only two codewords w1 and w2 such that d(w1,w2) = 3. (Thus, dmin = 3.) For example, we could let w1 = 000 and w2 = 111. With this code, we can correct any 1 error, or detect up to any 2 errors. codes correctable to w1 two errors codes correctable to w2 011 100 010 101 001 110 one error Valid codewords: 000 111 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

86 M. Frank, EEL3705 Digital Logic, Fall 2006
Gray Codes A binary Gray code for numbers (mod n) has the property that the codes for adjacent numbers differ only in 1 bit position. d(a, a+1 mod n) = 1. This property can help improve reliability of communication systems… Since if a continuous signal coding a word drifts by 1 unit, it changes only 1 bit of the coded value A 1-bit error can be detected and corrected relatively easily. It’s also useful if there is a need to ensure that a state “in between” two subsequent codewords is not mistaken for a different codeword. Disk spindle example For n=2k, a k-bit Gray code can be generating using the rule that the bits of the gray code word g representing the binary number b are gi = bibi+1 E.g., For k=2, the map b→g is 0 → 00, 1 → 01, 2 → 11, 3 → 10 For k=3 the sequence of g’s is: 000, 001, 011, 010, 110, 111, 101, 100 Later, we will also find that this code is useful in drawing Karnaugh maps for the optimization of digital circuits. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

87 The Hamming Code: An Error Correction Code based on Parity Bits
Adding n+1 parity bits to a (2n−1)-bit data sequence lets us detect and correct any single error in the data or parity bits. This is known as a Hamming code, and it is called a “perfect” code For n=4, the space blowup caused by the parity bits is 33.33% Overhead gets smaller as n increases. (e.g. n=10  1.07% overhead) p is the XOR of all data bits pi includes dj if bit i is 1 in the binary expansion of j If dj is altered, p indicates an error has occurred, and the pi together give the value of j. If pi is altered, then p indicates this, and pi can be regenerated If p is altered, the pi show this and p can be regenerated. Codeword for n=4: (d1,…,d15, p, p0, p1, p2, p3) Where p = d1d2…d14d15, p0 = d1d3d5d7d9d11d13d15, p1 = d2d3d6d7d10d11d14d15, p2 = d4d5d6d7d12d13d14d15, p3 = d8d9d10d11d12d13d14d15. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

88 Topics from Chapter 1 That we Omitted this Semester
More details about standard floating-point number formats (pp ) The standard IEEE-764 FP format is covered in more depth in EEL4713, Comp. Architecture More details about error detection and correction codes. Dr. Harvey occasionally teaches a special-topics course, “Error Control Codes” which covers this topic in depth. 11/15/2018 M. Frank, EEL3705 Digital Logic, Fall 2006


Download ppt "EEL 3705 / 3705L Digital Logic Design"

Similar presentations


Ads by Google