HO - Thinking Like A Computer Scientist
HO - Thinking Like A Computer Scientist
•
•
•
•
•
– –
–
–
Step 1. Fetch
Obtain program
instruction or data item
from memory
Step 4. Store Step 2.
Write result to Decode
memory Translate
instruction
into
Step 3. Execute commands
Carry out command
Step 1. Fetch
Obtain program
instruction or data item
from memory
Step 4. Store Step 2.
Write result to Decode
memory Translate
instruction
into
Step 3. Execute commands
Carry out command
What is it?
•
•
•
– …
– …
•
“There are only 10 types
of people in the world,
those who understand
binary, and those who
do not.”
• Repetitive division: 36 = 100100
36
Note: The remainders incurred when the given
18 0 decimal number is divided by 2 shall form the
9 0 binary equivalent. The division will only terminate
4 1 when the quotient becomes 0.
2 0
1 0
0 1
Challenge
•
–
–
–
–
–
•
1 1 0 0 1 0 1 1 0 0 1 1
+ +
0 1 0 0 1 1 1 1 0 1
1 1 1 0 1 1 1 0 1 0 0 0 0
1 0 1 1 0 0
+
1 1 0 1
1.)
3.)
1 1 0
+ 1 0 0 1 1
0 0 1 +
1 1 0 0 0
2.) 4.)
1 1 1 1 1
+ +
1 0 1 1 0
Multiplication
• Example:
a.
1 1 0 1 0 1
x
1 1
CARRY 1 1 1 0 1 0 1
+
1 1 0 1 0 1
1 0 0 1 1 1 1 1
c
1 0 1 1 0 0
+
1 0 1
1.)
3.)
1 1 0
x 1 1 0 1 1
1 1 x
1 0 0
2.) 4.)
1 1 1 0 1
x
1 0 x
1 0
• •
a. a.
b. b.
c. c.
d. d.
e. e.
Subtraction
• Examples:
a.
1 1 0 1 1 1
-
1 0 0 1 0 1
0 1 0 0 1 0
b.
borrow
0 10 0 10
1 0 0 1 1 0
-
1 0 1 0 1
0 1 0 0 0 1
Still on Subtraction
•
0 10
1 0 0 1
- 1 1 0 1
1 0 0
Negative Values in Binary Number
System
• Signed Magnitude (S.M.)
• One’s Complement (O.C.)
• Two’s Complement (T.C.)
– When working with the above, we restrict the
numbers in an n-bit system. In the next
slides, assume that we are working with a 6-bit
system
Signed Magnitude
•
001100 12
101100 -12
–
000101 5
100101 -5
One’s Complement
•
001100 12
–
110011 -12
000101 5
111010 -5
Two’s Complement
•
– 001100 12
110100 -12
000101 5
111011 -5
Still on Subtraction
•
–
•
–
•
–
•
•
•
•
•
•
•
•
•
•
– …
– …
•
–
•
–
–
–
–
–
•
79
9 7
• 1 1
0 1
•
–
–
–
–
–
…
• 101 1012
001 001 0012
• 110 001 0002
• 3 38
• 1 7 08
5 2 58
•
•
•
•
•
•
•
•
•
– …
– …
•
–
•
–
– Answers:
244
– 61
– 3053
– 428
251
•
538
33 10
• 2 1
0 2
•
– Answers:
– 2D16
– 6216
4016
– 41B16
– 93416
…
• 0101 0101
0001 0001 0001
• 0110 0001 0000
• 1 B16
• 7 816
1 5 516
•
•
•
187
AF4
1101110
233