Chapter 1 Digital Computers and Information Digital Computer

  • Slides: 17
Download presentation
Chapter 1 Digital Computers and Information

Chapter 1 Digital Computers and Information

Digital Computer Basics n Digital values represented as voltage values, e. g. n n

Digital Computer Basics n Digital values represented as voltage values, e. g. n n n Logic 1 is 4. 0 -5. 0 V Logic 0 is 0. 0 -1. 0 V Why digital? Why binary? n n Simplest Cheapest CSC 480 – Winter 2002

A Generic Computer n n n Memory = RAM, caches I/O = keyboard, terminal,

A Generic Computer n n n Memory = RAM, caches I/O = keyboard, terminal, hard disk CPU n n CSC 480 – Winter 2002 Datapath= performs basic instructions CPU = supervisor, flow MMU = memory management FPU = floating point specialist

Number Systems n Radix r number represented as: n n n n An-1. .

Number Systems n Radix r number represented as: n n n n An-1. . . A 1 A 0. A-1 A-2. . . A-m Value is An-1 rn-1 + An-2 rn-2 +. . . A 1 r 1 + A 0 r 0 + A-1 r-1 +. . . A–mr-m Digit range: 0 - (r-1) An-1 is the “most significant digit” A-m is the “least significant digit” Notation: (6342)7 – use parens and subscript to indicate number base, in this case 7 4 common bases: 2 (binary), 8 (octal), 10 (decimal), 16 (hex) CSC 480 – Winter 2002

Base R Wishlist We want to be able to “handle” radix R numbers, including:

Base R Wishlist We want to be able to “handle” radix R numbers, including: n n Decimal shortcut - Convert to decimal a number in any radix Power of 2 shortcut - Power of 2 conversions between binary, octal, and hex numbers General radix conversion - convert a number in radix R 1 to radix R 2 We also want to be able to perform the standard math operations CSC 480 – Winter 2002

Convert to Decimal n We use decimal (r=10), so conversion from other bases to

Convert to Decimal n We use decimal (r=10), so conversion from other bases to decimal is common. . . n n n Ex: Convert (43. 2)5 to decimal Trick: Just expand each digit. We know how to manipulate decimal numbers which makes this process “easy”. Ans: 4 * 5 + 3 * 1 + 2 *. 2 = 23. 4 Note 1: Conversion from decimal is handled by standard technique, no shortcut Note 2: We are lucky. We can easily convert to decimal to check our work! CSC 480 – Winter 2002

Convert to Decimal, cont n There is another way (shortcut? ) called Horner’s rule

Convert to Decimal, cont n There is another way (shortcut? ) called Horner’s rule (not in the text except as a homework problem W = an-1 for i=n-2 to 0 by – 1 w = w*r + ai n Ex: Convert (2504)6 to decimal 2 * 6 + 5 = 17 17 * 6 + 0 = 102 * 6 + 4 = 616 n This is actually more efficient as well CSC 480 – Winter 2002

Power of 2 Conversions n The trick(s) Base 8 (octal) is Base 2 “cubed”

Power of 2 Conversions n The trick(s) Base 8 (octal) is Base 2 “cubed” n n 24 = 16 So, 4 bits equals one hex digit Convert to Binary Ex: (743. 2)8 n Expand each octal digit into its 3 -bit value n Ans: (111 100 010)2 n 23 = 8 So, 3 bits equals one octal digit Base 16 (hex) is Base 2 to the 4 th power n n n Convert from Binary n n n CSC 480 – Winter 2002 Ex: (10010101)2 to hex Trick: Collapse each 4 bit group into its hex value Ans: (95)16

General Conversion, cont. n Don’t forget fractions n n n Handle fractional parts separately

General Conversion, cont. n Don’t forget fractions n n n Handle fractional parts separately Similar process as integer part, except multiply and use whole numbers, not remainders Ex. (0. 625)10 to binary 0. 625 * 2 = 1. 25, use 1 0. 25 * 2 = 0. 5, use 0 0. 5 * 2 = 1. 0, use 1 Answer is whole numbers in order: (101)2 Again, you can check work in decimal. CSC 480 – Winter 2002

General Number Conversion n n Trick: To convert to radix R, successively divide your

General Number Conversion n n Trick: To convert to radix R, successively divide your number by R and the remainders are your converted value. Ex: Convert (169)10 to octal 169 / 8 = 21 R 1 21 / 8 = 2 R 5 2 / 8 = 0 R 2 Answer is reverse of remainders (251)8 Check our work: (251)8 = 2*8*8 + 5*8 + 1 = 169 CSC 480 – Winter 2002

Arithmetic Operations We want to add, subtract and multiply numbers of radix R n

Arithmetic Operations We want to add, subtract and multiply numbers of radix R n Good news: Same basic rules as decimal math n Bad news: Your decimal brain may rebel at the non-decimal carries, borrows, etc. n More good news: Convert to decimal to verify your work CSC 480 – Winter 2002

Adding Let’s add: (3 A)16 + (69)16 n n Watch the carries! n n

Adding Let’s add: (3 A)16 + (69)16 n n Watch the carries! n n Carry value is now worth 16 (the base) Double check with decimal values CSC 480 – Winter 2002

Subtracting Let’s subtract: (69)16 - (3 A)16 n n Watch the borrows! n n

Subtracting Let’s subtract: (69)16 - (3 A)16 n n Watch the borrows! n n Borrow value is now worth 16 (the base) Double check with decimal values CSC 480 – Winter 2002

Multiplying Let’s multiply: (3 A)16 * (69)16 n n Labor-intensive, error-prone with multiple steps

Multiplying Let’s multiply: (3 A)16 * (69)16 n n Labor-intensive, error-prone with multiple steps CSC 480 – Winter 2002

Binary-coded Decimals n n n BCD = binary-coded decimal “Human” binary coding of decimal

Binary-coded Decimals n n n BCD = binary-coded decimal “Human” binary coding of decimal numbers Convert number one digit at a time: n n BCD addition n n Ex: 17 = 0001 0111 CSC 480 – Winter 2002 Add each digit separately Carry is “special” If sum for any digit >= 10, add 6 (0110) to sum to get proper BCD result Ex. 8 + 5 = 1000 + 0101 = 1101 (Add 0110!) = 0001 0011

Alphanumeric codes n ASCII – encoding for alphanumeric data n n n 7 bits

Alphanumeric codes n ASCII – encoding for alphanumeric data n n n 7 bits long Covers a-z, A-Z, 0 -9, !@#$ and many other special characters See table on page 21 for complete mapping 8 th bit often added for parity check Only for English-language characters CSC 480 – Winter 2002

Chapter 1 Summary n Most important: n n n Generic computer & information Understand

Chapter 1 Summary n Most important: n n n Generic computer & information Understand radix R number systems Radix conversion (general and shortcuts) Radix math operations BCD encoding and addition ASCII code basics CSC 480 – Winter 2002