Document 11444711

advertisement
Special Lecture Exercise for Lec02 (CS1102 - Section C01, CB1, CC1)
www.cs.cityu.edu.hk/~helena
Casual Discussion, Warm-up Questions, and Lecture Demo Exercises
1. Complete the following table to show the conversion between four number systems:
Decimal [Base 10] Digits: 0‐9 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Binary [Base 2] Digits: 0,1 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 Octal [Base 8] Digits: 0-7 0 1 2 3 4 5 6 7 10 11 12 13 14 15 Hexadecimal [Base 16] Digits: 0‐9,A,B,C,D,E,F 0 1 2 3 4 5 6 7 8 9 A B C 2. Complete the following Truth Table (1 means true; 0 means false) using the OR operation:
Input The entering passenger is: Output My action is: Elderly Give up my seat 0 0 1 1 Sick 0 1 0 1 ____ ____ ____ 1 3. Design of Logic Circuits -- A very simple example:
Suppose we need to build a logic circuit for the following Truth Table :
A 0 0 1 1 Input B 0 1 0 1 Output F 0 1 1 1 Your task: Decide which kind of gate to use (AND? OR? XOR? ..)
input
output
A
B
F
1
Special Lecture Exercise for Lec02 (CS1102 - Section C01, CB1, CC1)
www.cs.cityu.edu.hk/~helena
4. (i) Complete the table on the right which shows the powers of 2:
20 21 22 23 24 25 26 27 28 29 210 (ii). Fill in the blanks:
(a) 0 1 0 0 0 0 1 1 (2) = __________________(10)
(b) 1 1 1 1 0 0 1 1 (2) = __________________(16)
(c) 1 1 0 1 0 0 1 1 (2) = __________________(8)
= 1 = 2 = 4 = 8 = = = = = = = 5. [Slide 6 -- explained]
Why are followings most commonly used?
Number System
(Base 2) Binary
- 2 digits:
(Base 8) Octal
- 8 digits:
(Base 10) Decimal
- 10 digits:
(Base 16) Hexadecimal - 16 digits:
Reason to use
0,1
0-7
0-9
0-9,A-F
6. [Slide 7 -- more]
Choose "Least significant" or "Most significant"
to describe each underlined digit:
Note: significant means "important"
I have $375.15
Most / least significant digit 7. [Slide 8 -- explained]
(i) Complete the table on the right to show the negative powers of 2:
(ii) Fill in the blank: 101.1001(2) = ___________(10)
Most / least significant digit 20 = 1 2‐1 = 1 21 = 0.5 2‐2 = = 2‐3 = = 2‐4 = = 2
Special Lecture Exercise for Lec02 (CS1102 - Section C01, CB1, CC1)
www.cs.cityu.edu.hk/~helena
8. Summary / More practices on Binary Arithmetic
What you learn
[Slide 8] Conversion from Binary to Decimal
[Slide 9] Binary Addition (note: carry digits)
[Slide 9] Binary Subtraction (note: borrow digits)
[Slide 10] Binary Multiplication
[Slide 10] Binary Division
[Slide 11] Conversion from Decimal to Binary
(Whole numbers) Repeated division
[Slide 12] Conversion from Decimal to Binary
(Fraction part) Repeated multiplication
[Slide 13-14] To deal with -ve numbers
Using Two's Complement
More Examples, Practices
(a) 101.1001(2) = ____________(10)
(b) 0011(2) +0101(2) = ____________(2)
(c) 1001(2) -0011(2) = ____________(2)
(d) 101(2) x 110(2) = ____________(2)
(e) 111000(2) / 110(2) = _____________(2)
(f) 26(10) = _____________(2)
(g) 0.6(10) = _____________(2)
(h) 5 - 2 = _____________(2)
3
Special Lecture Exercise for Lec02 (CS1102 - Section C01, CB1, CC1)
www.cs.cityu.edu.hk/~helena
9. Fill in the blanks:
(i) Consider values >= 0
 2 bits can represent ________ different values (00,01,10,11, ie. 0 to 3)
 3 bits can represent ________ different values (000,001,010,011,100,101,110,111, ie. 0 to 7)
 4 bits can represent ________ different values (0000,0001,...1111, ie. 0 to 15)
 ___ bits can represent 256 different values (00000000 to 11111111, ie. 0 to 255)
(ii) Now consider using 2's complements to represent a range of -ve to + ve numbers [Slide #14]
 If we use 4 bits to represent a range of numbers in 2's complement, they can be -8(10) to 7(10)
 If we use 8 bits to represent a range of numbers in 2's complement, they can be -128(10) to ____(10)
 In 2's complement, The left-most bit is always __. (See slide #14)
10. [Slides 21-25] Draw the Truth Tables for the expressions:
F = (A AND B) OR C
F = A NAND B
Input A B Output F A Input B C Output F Fill in the blanks for the following expressions, according to the given Truth Tables:
F = A _____ ( B ____ C )
F = A _____ ( B ____ C )
Input Output A B C F 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 1 1 Input Output A B C F 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0 12. [Slide 28] Explain the steps to calculate 1 1 0 1 + 0 1 0 1
Ref: 4-bit full-adder
4
Special Lecture Exercise for Lec02 (CS1102 - Section C01, CB1, CC1)
www.cs.cityu.edu.hk/~helena
[From slides 22-24]
5
Download