CSE 111, Fall 2000

# Great Ideas in Computer Science

## Lecture Notes #3

#### (3.  Insight I, continued)

b) How to convert between decimal & binary

e.g., how to convert decimal 87
(= letter W, in ASCII)
to 8-bit binary (01010111)

i.e., how to code a decimal numeral with
only 2 objects

Note:  An 8-bit binary numeral has these places:

 ___ ___ ___ ___ ___ ___ ___ ___ 128s place 64s place 32s place 16s place 8s place 4s place 2s place 1s place

Note:    Max decimal numeral that can be
represented in 8 bits is:
11111111 = 128 + 64 + ... + 2 + 1 = 255

e.g., to convert 87 (decimal) to 8-bit binary:

1 2 3
Decimal Numeral How many of these? Bit
D = 87 128 0 = Q 87 / 128 = 0, R=87
R = 87 N = 64 1 = Q 87 / 64 = 1, R = 23
R = 23 N = 32 0 = Q 23 / 32 = 0, R = 23
R = 23 N = 16 1 = Q 23 / 16 = 1, R = 7
R = 7 N = 8 0 = Q 7 / 8 = 0, R = 7
R = 7 N = 4 1 = Q 7 / 4 = 1, R = 3
R = 3 N = 2 1 = Q 3 / 2 = 1, R = 1
R = 1 N = 1 1 = Q 1 / 1 = 1, R = 0 (so, stop)

So, 87 (decimal) = 01010111 (binary),
reading column 3 from the top down.

e.g., How to convert 8-bit binary 00101001
to decimal 41?         Easy!

 128s 64s 32s 16s 8s 4s 2s 1s 0 0 1 0 1 0 0 1 32 + 8 + 1 = 41 (!)

Link to the Binary Magic Trick.

c)    How to add binary numbers:

Easy!
(Just remember that 1+1 = 10 (= decimal 2))

 87 01010111 + 41 + 00101001 128 10000000

Multiplication is similar, even easier!:
In decimal, 2 * 2 = 4
(remember:  In computer science "*" = multiplication)
In binary, 10 * 10 = 100
(which is NOT  the same as decimal 10 * 10 = 100 (!) )

#### (Turing's insight about only needing 5 actions)

- Every algorithm can be expressed in a language
for a computer, called a Turing Machine (TM),
that consists of :
*    a tape (i.e., an unlimited supply of paper)
& whose only nouns are "0" and "1"
& whose only verbs (actions) are:
*    MOVELEFT
*    MOVERIGHT
*    PRINT-0
*    PRINT-1
*    ERASE

Schagrin, Morton L.; Dipert, Randall R.;
& Rapaport, William J. (1985),
Logic:  A Computer Approach
(New York:  McGraw-Hill)
in Lockwood Library, BC138 .S32 1985

-    We'll use Pascal, which is a much more
expressive language, but no more powerful

-    Church-Turing Thesis:
Everything that can be computed
can be computed by a TM

i.e., for each computable problem P,
there is a TM that can
compute P's solution
(n problems, n TMs)

-    Turing's Theorem:
There is a universal TM that can compute
anything that can be computed.

i.e., there is a universal TM, call it "U",
such that for each computable problem,
U can compute its solution
(1 TM, n problems)

-     Karel the Robot is a TM (of a special kind)

#### 5.  Insight III    (Boehm & Jacopini's Theorem)

-    The 3 (or 4) (or 5) ways of creating more
complex actions out of the 5 basic ones are:

*    sequence (do this; do that)

*    selection (or choice):
if such and such is the case (or is true),
then do this
else  do that

*    repetition (or looping):
while such and such is the case (or is true),
do this

(*    stop)

(*    define new actions by naming them
(procedures, or subroutines) )

-    These are the 3 basic features of Pascal
(& Karel) that we'll learn.