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 #8: Radix Conversion 11/28/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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

3 Base Conversion Methods
11/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

4 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

5 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

6 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

7 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

8 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

9 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

10 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

11 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

12 M. Frank, EEL3705 Digital Logic, Fall 2006
Method 4 Variation When converting to 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

13 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

14 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

15 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

16 A Modular Circuit to Convert from Base 2 to Base 10 (Binary to BCD)
We do division in old base (base 2). This can be viewed as using method 3 or 4. (Pull up bin_to_bcd project in Quartus to see details better.) 11/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

17 A different circuit for converting base 2 to base 10, using method 1
We can do the arithmetic in “base 10” by using special BCD adders… Add up powers of 2 represented in binary-coded decimal… Constants encoding the various powers of two in BCD 64 32 16 08 04 02 01 n6..0 n6 n5 n4 n3 n2 n1 n0 BCD + BCD + BCD + BCD + Each of these buses holds two 4-bit BCD digits Each of these adders adds two 2-digit BCD numbers BCD + bcd13..0, bcd03..0 11/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

18 Fixed-Width Binary Arithmetic and Overflow
11/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

19 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

20 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

21 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

22 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006

23 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/28/2018 M. Frank, EEL3705 Digital Logic, Fall 2006


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

Similar presentations


Ads by Google