1 / 45

EE2174: Digital Logic and Lab

EE2174: Digital Logic and Lab. Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number System. Overview. Digital Computers Number Systems Representations Conversions Arithmetic Operations Decimal Codes Alphanumeric Codes.

gavan
Télécharger la présentation

EE2174: Digital Logic and Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number System

  2. Overview • Digital Computers • Number Systems • Representations • Conversions • Arithmetic Operations • Decimal Codes • Alphanumeric Codes Chapter 1: Digital Computers and Information

  3. Digital Systems • Major characteristic • manipulation of discrete elements of information (any set restricted to a finite # of elements) • e.g. 10 decimal digits, 26 letters • Discrete elements (in digital systems) can be represented by signals (physical quantities). • Most common signals: electrical (voltage, current) Chapter 1: Digital Computers and Information

  4. Voltage Ranges The 2 binary values (HIGH, LOW) of a digital signal are represented by ranges of voltage values Chapter 1: Digital Computers and Information

  5. Information Representation • Binary signals (2 discrete values) • 0 and 1 (LOW and HIGH, FALSE and TRUE) • Binary quantity: binary digit/bit • Information: group of bits/words (size: 8, 16, 32, 64, …) • Digital hardware computes binary functions of binary numbers: • Combinational (memoryless) • Sequential (using memory) Chapter 1: Digital Computers and Information

  6. Number Systems • Representation of numbers • Radix: “base”, the primitive unit for group of numbers, e.g. for decimal arithmetic radix=10 (“base” 10) • For every system, we need arithmetic operations (addition, subtraction, multiplication) • Also, conversion from one base to the other Chapter 1: Digital Computers and Information

  7. Number Systems - Decimal • “base” 10 (radix is 10) • 10 digits: 0..9 • (251.3)10 = 2102 + 5101 + 1100 + 310-1 • Note: ‘.’ is called the radix point (decimal point for base 10) Chapter 1: Digital Computers and Information

  8. Number Systems – Decimal (cont.) • In general, a decimal number with n digits to the left of the decimal point, and m digits to the right of the decimal point is written as: An-1 An-2 … A1 A0 . A-1 A-2 … A-m+1 A-m where Ai is a coefficient between 0..9, and i denotes the weight (=10i) of Ai. Chapter 1: Digital Computers and Information

  9. Number Systems – Decimal (cont.) The value of An-1 An-2 … A1 A0 . A-1 A-2 … A-m+1 A-m is calculated by i=n-1..0(Ai  10i ) + i=-m..-1(Ai  10i ) Chapter 1: Digital Computers and Information

  10. Number Systems – General • “base” r (radix r) • r digits • N = An-1 rn-1 + An-2rn-2 +… + A1r +A0 + A-1 r-1 + A-2r-2 +… + A-m r-m Least Significant Bit (LSB) Most Significant Bit (MSB) Chapter 1: Digital Computers and Information

  11. Number Systems – General (cont.) • e.g. let r = 8 (312.5)8= 382 + 181 + 280 + 58-1 = (202.625)10 • Conversion from n-ary (any system with radix n) to decimal follows similar process as above Chapter 1: Digital Computers and Information

  12. Number Systems (cont.) • Most common number systems for computers: • Binary (r = 2) • Octal (r = 8) • Hexadecimal (r = 16) Chapter 1: Digital Computers and Information

  13. Binary Numbers-Base 2 • Computers represent all data as “strings of bits”, each bit being either 0 or 1 • “base” 2, with 2 digits: 0 and 1 • e.g. (101101.10)2 =125 + 024 + 123 + 122 + 021 + 120 + 12-1 + 02-2 (in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0 = (45.5)10 Chapter 1: Digital Computers and Information

  14. Binary Numbers-Base 2 (cont.) • e.g. (1001.011)2 =123 + 022 + 021 + 120 + 02-1 + 12-2 + 12-3 (in decimal) = 8 + 1 + 0.25 + 0.125 = (9.375)10 Chapter 1: Digital Computers and Information

  15. Powers of two Memorize at least through 216 Chapter 1: Digital Computers and Information

  16. Octal Numbers-Base 8 • “base” 8, with 8 digits: 0..7 • e.g. (762)8 =782 + 681 + 280 (in decimal) = 448 + 48 + 2 = (498)10 Chapter 1: Digital Computers and Information

  17. Hexadecimal Numbers-Base 16 • r = 16 • Digits (convention): 0..9, A, B, C, D, E, F • A=10, B=11, … , F = 15 • e.g. (3FB)16 = 3162 + 15161 + 11160 (in decimal) = 768 + 240 + 11 = (1019)10 Chapter 1: Digital Computers and Information

  18. Base Conversions • Any base r decimal – Easy! (already covered, see slides 13-14, 16-17, 19-20) • Decimal  Binary • Octal  Binary • Hex  Binary • Decimal  Any base r Chapter 1: Digital Computers and Information

  19. Decimal to Binary Let N be a decimal number. • Find the greatest number that is a power of 2 and when subtracted from N it produces a positive difference N1 • Put a 1 in the MSB • Repeat Step 1, starting from N1 and finding difference N2. Put a 1 in the corresponding bit. Stop when the difference is zero. Chapter 1: Digital Computers and Information

  20. Decimal to Binary (cont.) e.g. N = (717)10 717 – 512 = 205 = N1 512 = 29 205 –128 = 77 = N2 128 = 27 77 – 64 = 13 = N3 64 = 26 13 – 8 = 5 = N4 8 = 23 5 – 4 = 1 = N5 4 = 22 1 – 1 = 0 = N6 1 = 20  (717)10 = 29 + 27 + 26 + 23 + 22 + 20 = ( 1 0 1 1 0 0 1 1 0 1)2 Chapter 1: Digital Computers and Information

  21. Binary to Octal and Hex • Octal: 8 = 23 every 3 binary bits convert 1 octal • Hex: 16 = 24 every 4 binary bits convert 1 hex Chapter 1: Digital Computers and Information

  22. Binary  Octal (011 010 101 000 . 111 101 011 100)2 ( 3 2 5 0 . 7 5 3 4 )8 Chapter 1: Digital Computers and Information

  23. Binary  Hex ( 0110 1010 1000 . 1111 0101 1100 )2 ( 6 A 8 . F 5 C )16 Chapter 1: Digital Computers and Information

  24. Octal  Hex Go through Binary! Hex  Binary  Octal Octal  Binary  Hex Chapter 1: Digital Computers and Information

  25. Convert Decimal to any base r • Integer part: Divide by the base, keep track of remainder, and read-up • e.g. (153)10 = ( ? )8 , r = 8 153 / 8 = 19 + 1/8 rem = 1 LSB 19 / 8 = 2 + 3/8 rem = 3 2 / 8 = 0 + 2/8 rem = 2 MSB  (153)10 = ( 231)8 stop Chapter 1: Digital Computers and Information

  26. Convert Decimal to any base r • Fractional part: Multiply by the base, keep track of integer part, and read-down • e.g. (0.78125)10 = ( ? )16 , r = 16 0.7812516 = 12.5 integer = 12 = C MSB 0.5  16 = 8.0 integer = 8 = 8 LSB  (0.78125)10 = (0.C8)16 stop Chapter 1: Digital Computers and Information

  27. Binary Arithmetic Operations:Addition • Follow same rules as in decimal addition, with the difference that when sum is 2 indicates a carry (not a 10) • Learn new carry rules • 0+0 = 0c0 (sum 0 with carry 0) • 0+1 = 1+0 = 1c0 • 1+1 = 0c1 • 1+1+1 = 1c1 Chapter 1: Digital Computers and Information

  28. Binary Arithmetic Operations:Addition (cont.) • “Half addition” (rightmost bit position, aka LSB): only 2 bits are added, yielding a sum and a carry • “Full addition” (remaining positions): three bits are added, yielding a sum and a carry • In Chapter 3, we’ll see many different hardware implementations of half-adders and full-adders Chapter 1: Digital Computers and Information

  29. Binary Arithmetic Operations:Subtraction • Learn new borrow rules • 0-0 = 1-1 = 0b0 (result 0 with borrow 0) • 1-0 = 1b0 • 0-1 = 1b1 • … Chapter 1: Digital Computers and Information

  30. Keys to Success • Recall and use the “algorithms” you use to perform base-10 arithmetic. • Generalize them to the base in use (carry, borrow rules change) • Preserve the base! In binary, 1+1=10 Chapter 1: Digital Computers and Information

  31. Two’s complement Arithmetic • Two’s complement of a binary number is computed as complementing each bit and add 1 • It is used for subtrahend in subtraction • For example, (3)10=(011)2, so (-3)10=(100+1)2 • (111)-(011)=(111)+(101)=(1100) removing the leading carry = (100) • Why? • x-(011)=x-[111-100]=x-[1000-1-100]=x-(100+1)-1000

  32. Binary Arithmetic Operations: Multiplication • Shift-and-add algorithm, as in base 10 • Check: 13 * 6 = 78 Chapter 1: Digital Computers and Information

  33. CODES • Representations of info (set) obtained by associating one or more codewords (a binary pattern/string) with each element in the set • n-bit binary code: a group of n bits that can encode up to 2 n distinct elements e.g. A set of 4 distinct numbers can be represented by 2-bit codes s.t. each number in the set is assigned exactly one of the combinations/codes in {00,01,10,11} Chapter 1: Digital Computers and Information

  34. CODES (cont.) • To encode m distinct elements with an n-bit code: 2n>= m • Note: The codeword associated with each number is obtained by coding the number, not converting the number to binary. • We will see: BCD, ASCII, Unicode Chapter 1: Digital Computers and Information

  35. Binary-Coded Decimal (BCD) • A decimal code: Decimal numbers (0..9) are coded using 4-bit distinct binary words • Observe that the codes 1010 .. 1111 (decimal 10..15) are NOT represented (invalid BCD codes) Chapter 1: Digital Computers and Information

  36. Binary-Coded Decimal (cont.) • To code a number with n decimal digits, we need 4n bits in BCD e.g. (365)10 = (0011 0110 0101)BCD • This is different to converting to binary, which is (365)10 = (101101101)2 • Clearly, BCD requires more bits. BUT, it is easier to understand/interpret Chapter 1: Digital Computers and Information

  37. BCD Addition • When 2 BCD codes are added: • If the binary sum is less than 1010 (9 in decimal), the corresponding BCD sum digit is correct • If the binary sum is equal or more than 1010, must add 0110 (6 in decimal) to the corresponding BCD sum digit in order to produce the correct carry into the digit to the left Chapter 1: Digital Computers and Information

  38. BCD Addition (cont.) • Example: Add 448 and 489 in BCD. 0100 0100 1000 (448 in BCD) 0100 1000 1001(489 in BCD) 10001 (greater than 9, add 6) 1 0111 (carry 1 into middle digit) 1101 (greater than 9, add 6) 1001 1 0011 (carry 1 into leftmost digit) 1001 0011 0111 (BCD coding of 93710) Chapter 1: Digital Computers and Information

  39. ASCII character code • We also need to represent letters and other symbols  alphanumeric codes • ASCII = American Standard Code for Information Interchange. Also know as Western European • It contains 128 characters: • 94 printable ( 26 upper case and 26 lower case letters, 10 digits, 32 special symbols) • 34 non-printable (for control functions) • Uses 7-bit binary codes to represent each of the 128 characters Chapter 1: Digital Computers and Information

  40. ASCII Table Chapter 1: Digital Computers and Information

  41. Unicode • Established standard (16-bit alphanumeric code) for international character sets • Since is 16-bit, it has 65,536 codes • Represented by 4 Hex digits • ASCII is between 000016 .. 007B16 Chapter 1: Digital Computers and Information

  42. Unicode Table (first 191 char.) Chapter 1: Digital Computers and Information

  43. ASCII Parity Bit • Parity coding is used to detect errors in data communication and processing • An 8th bit is added to the 7-bit ASCII code • Even (Odd) parity: set the parity bit so as to make the # of 1’s in the 8-bit code even (odd) Chapter 1: Digital Computers and Information

  44. ASCII Parity Bit (cont.) • For example: • Make the 7-bit code 1011011 an 8-bit even parity code  11011011 • Make the 7-bit code 1011011 an 8-bit odd parity code  01011011 • Both even and odd parity codes can detect an odd number of error. An even number of errors goes undetected. Chapter 1: Digital Computers and Information

  45. Summary Arithmetic Conversion between different number system Binary Arithmetic

More Related