Download presentation
Presentation is loading. Please wait.
Published bySibyl Cain Modified over 9 years ago
1
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number System
2
7-Oct-15 PJF - 2Chapter 1: Digital Computers and Information Overview Digital Computers Digital Computers Number Systems Number Systems Representations Representations Conversions Conversions Arithmetic Operations Arithmetic Operations Decimal Codes Decimal Codes Alphanumeric Codes Alphanumeric Codes
3
7-Oct-15 PJF - 3Chapter 1: Digital Computers and Information Digital Systems Major characteristic Major characteristic manipulation of discrete elements of information (any set restricted to a finite # of elements) manipulation of discrete elements of information (any set restricted to a finite # of elements) e.g. 10 decimal digits, 26 letters e.g. 10 decimal digits, 26 letters Discrete elements (in digital systems) can be represented by signals (physical quantities). Discrete elements (in digital systems) can be represented by signals (physical quantities). Most common signals: electrical (voltage, current) Most common signals: electrical (voltage, current)
4
7-Oct-15 PJF - 4Chapter 1: Digital Computers and Information Voltage Ranges The 2 binary values (HIGH, LOW) of a digital signal are represented by ranges of voltage values
5
7-Oct-15 PJF - 5Chapter 1: Digital Computers and Information Information Representation Binary signals (2 discrete values) Binary signals (2 discrete values) 0 and 1 (LOW and HIGH, FALSE and TRUE) 0 and 1 (LOW and HIGH, FALSE and TRUE) Binary quantity: binary digit/bit Binary quantity: binary digit/bit Information: group of bits/words (size: 8, 16, 32, 64, …) Information: group of bits/words (size: 8, 16, 32, 64, …) Digital hardware computes binary functions of binary numbers: Digital hardware computes binary functions of binary numbers: Combinational (memoryless) Combinational (memoryless) Sequential (using memory) Sequential (using memory)
6
7-Oct-15 PJF - 6Chapter 1: Digital Computers and Information Number Systems Representation of numbers Representation of numbers Radix: “base”, the primitive unit for group of numbers, e.g. for decimal arithmetic radix=10 (“base” 10) 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) For every system, we need arithmetic operations (addition, subtraction, multiplication) Also, conversion from one base to the other Also, conversion from one base to the other
7
7-Oct-15 PJF - 7Chapter 1: Digital Computers and Information Number Systems - Decimal “base” 10 (radix is 10) “base” 10 (radix is 10) 10 digits: 0..9 10 digits: 0..9 (251.3) 10 = 2 10 2 + 5 10 1 + 1 10 0 + 3 10 -1 (251.3) 10 = 2 10 2 + 5 10 1 + 1 10 0 + 3 10 -1 Note: ‘.’ is called the radix point (decimal point for base 10) Note: ‘.’ is called the radix point (decimal point for base 10)
8
7-Oct-15 PJF - 8Chapter 1: Digital Computers and Information 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: 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: A n-1 A n-2 … A 1 A 0. A -1 A -2 … A -m+1 A -m where A i is a coefficient between 0..9, and i denotes the weight (=10 i ) of A i. and i denotes the weight (=10 i ) of A i.
9
7-Oct-15 PJF - 9Chapter 1: Digital Computers and Information Number Systems – Decimal (cont.) The value of A n-1 A n-2 … A 1 A 0. A -1 A -2 … A -m+1 A -m is calculated by i=n-1..0 (A i 10 i ) + i=-m..-1 (A i 10 i )
10
7-Oct-15 PJF - 10Chapter 1: Digital Computers and Information Number Systems – General “base” r (radix r) “base” r (radix r) r digits r digits N = A n-1 r n-1 + A n-2 r n-2 +… + A 1 r + A 0 + N = A n-1 r n-1 + A n-2 r n-2 +… + A 1 r + A 0 + A -1 r -1 + A -2 r -2 +… + A -m r -m A -1 r -1 + A -2 r -2 +… + A -m r -m Most Significant Bit (MSB) Least Significant Bit (LSB)
11
7-Oct-15 PJF - 11Chapter 1: Digital Computers and Information Number Systems – General (cont.) e.g. let r = 8 e.g. let r = 8 (312.5) 8 = 3 8 2 + 1 8 1 + 2 8 0 + 5 8 -1 = (202.625) 10 = (202.625) 10 Conversion from n-ary (any system with radix n) to decimal follows similar process as above Conversion from n-ary (any system with radix n) to decimal follows similar process as above
12
7-Oct-15 PJF - 12Chapter 1: Digital Computers and Information Number Systems (cont.) Most common number systems for computers: Most common number systems for computers: Binary (r = 2) Binary (r = 2) Octal (r = 8) Octal (r = 8) Hexadecimal (r = 16) Hexadecimal (r = 16)
13
7-Oct-15 PJF - 13Chapter 1: Digital Computers and Information Binary Numbers-Base 2 Computers represent all data as “strings of bits”, each bit being either 0 or 1 Computers represent all data as “strings of bits”, each bit being either 0 or 1 “base” 2, with 2 digits: 0 and 1 “base” 2, with 2 digits: 0 and 1 e.g. e.g. (101101.10) 2 = 1 2 5 + 0 2 4 + 1 2 3 + 1 2 2 + 0 2 1 + 1 2 0 + 1 2 -1 + 0 2 -2 (101101.10) 2 = 1 2 5 + 0 2 4 + 1 2 3 + 1 2 2 + 0 2 1 + 1 2 0 + 1 2 -1 + 0 2 -2 (in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0 (in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0 = (45.5) 10 = (45.5) 10
14
7-Oct-15 PJF - 14Chapter 1: Digital Computers and Information Binary Numbers-Base 2 (cont.) e.g. e.g. (1001.011) 2 = 1 2 3 + 0 2 2 + 0 2 1 + 1 2 0 + 0 2 -1 + 1 2 -2 + 1 2 -3 (1001.011) 2 = 1 2 3 + 0 2 2 + 0 2 1 + 1 2 0 + 0 2 -1 + 1 2 -2 + 1 2 -3 (in decimal) = 8 + 1 + 0.25 + 0.125 (in decimal) = 8 + 1 + 0.25 + 0.125 = (9.375) 10 = (9.375) 10
15
7-Oct-15 PJF - 15Chapter 1: Digital Computers and Information Powers of two Memorize at least through 2 16
16
7-Oct-15 PJF - 16Chapter 1: Digital Computers and Information Octal Numbers-Base 8 “base” 8, with 8 digits: 0..7 “base” 8, with 8 digits: 0..7 e.g. e.g. (762) 8 = 7 8 2 + 6 8 1 + 2 8 0 (762) 8 = 7 8 2 + 6 8 1 + 2 8 0 (in decimal) = 448 + 48 + 2 = (498) 10 = (498) 10
17
7-Oct-15 PJF - 17Chapter 1: Digital Computers and Information Hexadecimal Numbers-Base 16 r = 16 r = 16 Digits (convention): 0..9, A, B, C, D, E, F Digits (convention): 0..9, A, B, C, D, E, F A=10, B=11, …, F = 15 A=10, B=11, …, F = 15 e.g. e.g. (3FB) 16 = 3 16 2 + 15 16 1 + 11 16 0 (3FB) 16 = 3 16 2 + 15 16 1 + 11 16 0 (in decimal) = 768 + 240 + 11 = (1019) 10 = (1019) 10
18
7-Oct-15 PJF - 18Chapter 1: Digital Computers and Information Base Conversions Any base r decimal – Easy! (already covered, see slides 13-14, 16-17, 19-20) Any base r decimal – Easy! (already covered, see slides 13-14, 16-17, 19-20) Decimal Binary Decimal Binary Octal Binary Octal Binary Hex Binary Hex Binary Decimal Any base r Decimal Any base r
19
7-Oct-15 PJF - 19Chapter 1: Digital Computers and Information Decimal to Binary Let N be a decimal number. 1. Find the greatest number that is a power of 2 and when subtracted from N it produces a positive difference N 1 2. Put a 1 in the MSB 3. Repeat Step 1, starting from N 1 and finding difference N 2. Put a 1 in the corresponding bit. Stop when the difference is zero.
20
7-Oct-15 PJF - 20Chapter 1: Digital Computers and Information Decimal to Binary (cont.) e.g. N = (717) 10 717 – 512 = 205 = N 1 512 = 2 9 205 –128 = 77 = N 2 128 = 2 7 77 – 64 = 13 = N 3 64 = 2 6 77 – 64 = 13 = N 3 64 = 2 6 13 – 8 = 5 = N 4 8 = 2 3 13 – 8 = 5 = N 4 8 = 2 3 5 – 4 = 1 = N 5 4 = 2 2 5 – 4 = 1 = N 5 4 = 2 2 1 – 1 = 0 = N 6 1 = 2 0 1 – 1 = 0 = N 6 1 = 2 0 (717) 10 = 2 9 + 2 7 + 2 6 + 2 3 + 2 2 + 2 0 = ( 1 0 1 1 0 0 1 1 0 1) 2 = ( 1 0 1 1 0 0 1 1 0 1) 2
21
7-Oct-15 PJF - 21Chapter 1: Digital Computers and Information Binary to Octal and Hex Octal: Octal: 8 = 2 3 every 3 binary bits convert 1 octal Hex: Hex: 16 = 2 4 every 4 binary bits convert 1 hex
22
7-Oct-15 PJF - 22Chapter 1: Digital Computers and Information Binary Octal (011 010 101 000. 111 101 011 100) 2 ( 3 2 5 0. 7 5 3 4 ) 8
23
7-Oct-15 PJF - 23Chapter 1: Digital Computers and Information Binary Hex ( 6 A8. F 5 C ) 16 ( 0110 1010 1000. 1111 0101 1100 ) 2
24
7-Oct-15 PJF - 24Chapter 1: Digital Computers and Information Octal Hex Go through Binary! Hex Binary Octal Octal Binary Hex
25
7-Oct-15 PJF - 25Chapter 1: Digital Computers and Information Convert Decimal to any base r Integer part: Divide by the base, keep track of remainder, and read-up Integer part: Divide by the base, keep track of remainder, and read-up e.g. (153) 10 = ( ? ) 8, r = 8 e.g. (153) 10 = ( ? ) 8, r = 8 153 / 8 = 19 + 1/8rem = 1 LSB 19 / 8 = 2 + 3/8rem = 3 19 / 8 = 2 + 3/8rem = 3 2 / 8 = 0 + 2/8rem = 2 MSB 2 / 8 = 0 + 2/8rem = 2 MSB (153) 10 = ( 231) 8 stop
26
7-Oct-15 PJF - 26Chapter 1: Digital Computers and Information Convert Decimal to any base r Fractional part: Multiply by the base, keep track of integer part, and read-down Fractional part: Multiply by the base, keep track of integer part, and read-down e.g. (0.78125) 10 = ( ? ) 16, r = 16 e.g. (0.78125) 10 = ( ? ) 16, r = 16 0.78125 16 = 12.5 integer = 12 = CMSB 0.78125 16 = 12.5 integer = 12 = CMSB 0.5 16 = 8.0 integer = 8 = 8 LSB (0.78125) 10 = (0.C8) 16 stop
27
7-Oct-15 PJF - 27Chapter 1: Digital Computers and Information 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) 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 Learn new carry rules 0+0 = 0c0 (sum 0 with carry 0) 0+0 = 0c0 (sum 0 with carry 0) 0+1 = 1+0 = 1c0 0+1 = 1+0 = 1c0 1+1 = 0c1 1+1 = 0c1 1+1+1 = 1c1 1+1+1 = 1c1 Carry111110 Augend001001 Addend011111 Result101000
28
7-Oct-15 PJF - 28Chapter 1: Digital Computers and Information Binary Arithmetic Operations: Addition (cont.) “Half addition” (rightmost bit position, aka LSB): only 2 bits are added, yielding a sum and a carry “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 “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 In Chapter 3, we’ll see many different hardware implementations of half-adders and full-adders
29
7-Oct-15 PJF - 29Chapter 1: Digital Computers and Information Binary Arithmetic Operations: Subtraction Learn new borrow rules Learn new borrow rules 0-0 = 1-1 = 0b0 (result 0 with borrow 0) 0-0 = 1-1 = 0b0 (result 0 with borrow 0) 1-0 = 1b0 1-0 = 1b0 0-1 = 1b1 0-1 = 1b1 … Borrow1100 Minuend11011 Subtrahend01101 Result01110
30
7-Oct-15 PJF - 30Chapter 1: Digital Computers and Information Keys to Success Recall and use the “algorithms” you use to perform base-10 arithmetic. Recall and use the “algorithms” you use to perform base-10 arithmetic. Generalize them to the base in use (carry, borrow rules change) Generalize them to the base in use (carry, borrow rules change) Preserve the base! In binary, 1+1=10 Preserve the base! In binary, 1+1=10
31
Two’s complement Two’s complement of a binary number is computed as complementing each bit and add 1 Two’s complement of a binary number is computed as complementing each bit and add 1 It is used for subtrahend in subtraction It is used for subtrahend in subtraction For example, (3) 10 =(011) 2, so (-3) 10 =(100+1) 2 For example, (3) 10 =(011) 2, so (-3) 10 =(100+1) 2 (111)-(011)=(111)+(101)=(1100) removing the leading carry = (100) (111)-(011)=(111)+(101)=(1100) removing the leading carry = (100) Why? Why? x-(011)=x-[111-100]=x-[1000-1-100]=x- (100+1)-1000 x-(011)=x-[111-100]=x-[1000-1-100]=x- (100+1)-1000 7-Oct-15 PJF - 31Arithmetic
32
7-Oct-15 PJF - 32Chapter 1: Digital Computers and Information Binary Arithmetic Operations: Multiplication Shift-and-add algorithm, as in base 10 Shift-and-add algorithm, as in base 10 Check: 13 * 6 = 78 Check: 13 * 6 = 78 M’cand0001101 M’plier0000110 (1)0000000 (2)0011010 (3)0110100 Sum1001110
33
7-Oct-15 PJF - 33Chapter 1: Digital Computers and Information CODES Representations of info (set) obtained by associating one or more codewords (a binary pattern/string) with each element in the set 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 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}
34
7-Oct-15 PJF - 34Chapter 1: Digital Computers and Information CODES (cont.) To encode m distinct elements with an n-bit code: 2 n >= m To encode m distinct elements with an n-bit code: 2 n >= m Note: The codeword associated with each number is obtained by coding the number, not converting the number to binary. 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 We will see: BCD, ASCII, Unicode
35
7-Oct-15 PJF - 35Chapter 1: Digital Computers and Information Binary-Coded Decimal (BCD) A decimal code: Decimal numbers (0..9) are coded using 4-bit distinct binary words 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) Observe that the codes 1010.. 1111 (decimal 10..15) are NOT represented (invalid BCD codes)
36
7-Oct-15 PJF - 36Chapter 1: Digital Computers and Information Binary-Coded Decimal (cont.) To code a number with n decimal digits, we need 4n bits in BCD 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 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 Clearly, BCD requires more bits. BUT, it is easier to understand/interpret
37
7-Oct-15 PJF - 37Chapter 1: Digital Computers and Information BCD Addition When 2 BCD codes are added: 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 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 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
38
7-Oct-15 PJF - 38Chapter 1: Digital Computers and Information BCD Addition (cont.) Example: Add 448 and 489 in BCD. 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) 10001 (greater than 9, add 6) 1 0111 (carry 1 into middle digit) 1 0111 (carry 1 into middle digit) 1101 (greater than 9, add 6) 1101 (greater than 9, add 6) 1001 1 0011 (carry 1 into leftmost digit) 1001 1 0011 (carry 1 into leftmost digit) 1001 0011 0111 (BCD coding of 937 10 )
39
7-Oct-15 PJF - 39Chapter 1: Digital Computers and Information ASCII character code We also need to represent letters and other symbols alphanumeric codes We also need to represent letters and other symbols alphanumeric codes ASCII = American Standard Code for Information Interchange. Also know as Western European ASCII = American Standard Code for Information Interchange. Also know as Western European It contains 128 characters: It contains 128 characters: 94 printable ( 26 upper case and 26 lower case letters, 10 digits, 32 special symbols) 94 printable ( 26 upper case and 26 lower case letters, 10 digits, 32 special symbols) 34 non-printable (for control functions) 34 non-printable (for control functions) Uses 7-bit binary codes to represent each of the 128 characters Uses 7-bit binary codes to represent each of the 128 characters
40
7-Oct-15 PJF - 40Chapter 1: Digital Computers and Information ASCII Table
41
7-Oct-15 PJF - 41Chapter 1: Digital Computers and Information Unicode Established standard (16-bit alphanumeric code) for international character sets Established standard (16-bit alphanumeric code) for international character sets Since is 16-bit, it has 65,536 codes Since is 16-bit, it has 65,536 codes Represented by 4 Hex digits Represented by 4 Hex digits ASCII is between 0000 16.. 007B 16 ASCII is between 0000 16.. 007B 16
42
7-Oct-15 PJF - 42Chapter 1: Digital Computers and Information Unicode Table (first 191 char.)
43
7-Oct-15 PJF - 43Chapter 1: Digital Computers and Information ASCII Parity Bit Parity coding is used to detect errors in data communication and processing Parity coding is used to detect errors in data communication and processing An 8 th bit is added to the 7-bit ASCII code An 8 th 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) Even (Odd) parity: set the parity bit so as to make the # of 1’s in the 8-bit code even (odd)
44
7-Oct-15 PJF - 44Chapter 1: Digital Computers and Information ASCII Parity Bit (cont.) For example: For example: Make the 7-bit code 1011011 an 8-bit even parity code 11011011 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 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. Both even and odd parity codes can detect an odd number of error. An even number of errors goes undetected.
45
Summary Conversion between different number system Conversion between different number system Binary Arithmetic Binary Arithmetic 7-Oct-15 PJF - 45Arithmetic
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.