Download Chapter 1 - williamt.com

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Chapter 1
Digital Computers
and Information
Digital Computer Basics

Digital values
represented as
voltage values, e.g.



Logic 1 is 4.0-5.0 V
Logic 0 is 0.0-1.0 V
Why digital? Why
binary?


Simplest
Cheapest
CSC 480 – Winter 2002
A Generic Computer



Memory = RAM,
caches
I/O = keyboard,
terminal, hard disk
CPU




CSC 480 – Winter 2002
Datapath= performs
basic instructions
CPU = supervisor, flow
MMU = memory
management
FPU = floating point
specialist
Number Systems

Radix r number represented as:







An-1 ... A1 A0 . A-1 A-2 ... A-m
Value is An-1rn-1 + An-2rn-2 + ... A1r1 +
A0r0 + A-1r-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:




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 R1 to radix R2
We also want to be able to perform the
standard math operations
CSC 480 – Winter 2002
Convert to Decimal

We use decimal (r=10), so conversion from
other bases to decimal is common...





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

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

Ex: Convert (2504)6 to decimal
2 * 6 + 5 = 17
17 * 6 + 0 = 102
102 * 6 + 4 = 616

This is actually more efficient as
well
CSC 480 – Winter 2002
Power of 2 Conversions

The trick(s)
Base 8 (octal) is Base
2 “cubed”




24 = 16
So, 4 bits equals
one hex digit
Convert to Binary
Ex: (743.2)8
 Expand each octal digit
into its 3-bit value
 Ans:
(111 100 010. 010)2

23 = 8
So, 3 bits equals
one octal digit
Base 16 (hex) is Base 2
to the 4th power



Convert from Binary



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.

Don’t forget fractions



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


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 R1
21 / 8 = 2 R5
2 / 8 = 0 R2
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
 Good news: Same basic rules as decimal
math
 Bad news: Your decimal brain may rebel at
the non-decimal carries, borrows, etc.
 More good news: Convert to decimal to
verify your work
CSC 480 – Winter 2002
Adding
Let’s add:
(3A)16 + (69)16


Watch the carries!


Carry value is now
worth 16 (the base)
Double check with
decimal values
CSC 480 – Winter 2002
Subtracting
Let’s subtract:
(69)16 - (3A)16


Watch the
borrows!


Borrow value is now
worth 16 (the base)
Double check with
decimal values
CSC 480 – Winter 2002
Multiplying
Let’s multiply:
(3A)16 * (69)16
 Labor-intensive, error-prone with multiple
steps

CSC 480 – Winter 2002
Binary-coded Decimals



BCD = binary-coded
decimal
“Human” binary
coding of decimal
numbers
Convert number
one digit at a time:


BCD addition




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

ASCII – encoding for alphanumeric
data





7 bits long
Covers a-z, A-Z, 0-9, !@#$ and many
other special characters
See table on page 21 for complete
mapping
8th bit often added for parity check
Only for English-language characters
CSC 480 – Winter 2002
Chapter 1 Summary

Most important:






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