======================================
Assignment #02 - Logic and Binary Math
======================================
- Ian! D. Allen - idallen@idallen.ca - www.idallen.com
1. Develop a binary encoding scheme which could be used to encode a field to
represent one of the months of the year. Use the minimum number of bits.
ANSWER: 4 bits encodes 16 things; January is 0000, December is 1011
2. What is the minimum number of binary bits needed to represent 51,629 items?
ANSWER: 16 bits, unsigned
In a 10-bit storage cell:
3. What is the bit number of the highest (most significant) bit?
ANSWER: bit 9
4. If you write down the 10 bits on paper, is the highest bit written on
the left or the right of the 10 bits?
ANSWER: to the left, e.g. 100000000b
5. In unsigned binary encoding, what is the weight of this high bit,
expressed both as a power of two and in decimal?
ANSWERS: 9th bit is 2**9 is 512
6. Assuming an 8-bit word, show, in binary, how such a word would be
encoded to represent the decimal number 96 using unsigned binary encoding.
ANSWER: 01100000
7. What is the minimum number of binary bits needed to represent 96 items?
ANSWER: 7 (2**7 = 128 items)
8. Assuming unsigned binary encoding, what decimal value is represented
by the binary pattern: 1 0 1 0 0 0 1 1 ?
ANSWER: 128 + 32 + 2 + 1 = 163
9. Define the term "word" as it is used in computer architecture.
ANSWER: typical "integer" type, e.g. the collection of bits used by a
particular processor to represent its basic numeric form.
10. For each of the following circuit descriptions, draw the circuit
(or use ASCII art - see the Appendix Example below) and then create the
complete truth table showing input and output values for all possible
input combinations. You don't have to hand in your circuit drawing,
unless you want to use ASCII art to create it:
Circuit 1
A. Input
B. Input
C. NOT from B
D. AND from A and C
E. OUTPUT from D
ANSWER:
+---+ A B || c d E
A --------|> | ----------------
| A | d 0 0 || 1 0 0
+---| N |>------- E 0 1 || 0 0 0
| N | D | 1 0 || 1 1 1
B ----|>O |c | 1 1 || 0 0 0
| T +---+
+---+
Circuit 2
A. Input
B. Input
C. Input
D. OR from A and B
E. NOT from B
F. XOR from C and E
G. Output from D
H. Output from F
ANSWER:
+---+ A B C || d e f G H
| | -------------------------
A -----|> | d 0 0 0 || 0 1 1 0 1
| O |>------- G 0 0 1 || 0 1 0 0 0
B --+--|>R | 0 1 0 || 1 0 0 1 0
| | | 0 1 1 || 1 0 1 1 1
| +---+ 1 0 0 || 1 1 1 1 1
| 1 0 1 || 1 1 0 1 0
| +---+ 1 1 0 || 1 0 0 1 0
| |eN |---+ 1 1 1 || 1 0 1 1 1
+--|>O |> |
| T | X | f
+---+ O |>------- H
| R |
C ---------|> |
+---+
11. Perform the following additions and subtractions in binary, assuming
a 6 bit word. Show the result value plus the values of the Zero, Sign,
Carry, and Overflow flag values for each (five answers for each).
011010 011010
+ 001111 - 001111
ANSWERS:
101001 001011
Carry: 0/off Carry: 0/off
Zero: 0/off Zero: 0/off
Sign: 1/on Sign: 0/off
Over: 1/on Over: 0/off
010111 010110
+ 101001 - 010110
ANSWERS:
000000 000000
Carry: 1/on Carry: 0/off
Zero: 1/on Zero: 1/on
Sign: 0/off Sign: 0/off
Over: 0/off Over: 0/off
12. Convert the following decimal values into 2's complement (signed) form,
assuming a 12-bit word. Show your results in both binary and hexadecimal.
a. -1 ANSWERS: 111111111111b = FFFh
b. +693 ANSWERS: 001010110101b = 2B5h
c. -693 ANSWERS: 110101001011b = D4Bh
d. 2048 ANSWERS: too big; max 12-bit signed is 2047 or (2**11)-1
e. -2048 ANSWERS: 100000000000b = 800h
f. 4097 ANSWERS: too big
13. Perform the indicated arithmetic in hexadecimal, assuming a 12-bit word;
show the hexadecimal result plus the states of the Zero, Sign, Carry
and Overflow flags (five answers for each).
D8A 948 C8B ACE
+276 -35A +839 -BDF
ANSWERS:
000 5EE 4C4 EEF
Z:1 Z:0 Z:0 Z:0
S:0 S:0 S:0 S:1
C:1 C:0 C:1 C:1
V:0 V:1 V:1 V:0
--
| Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada
| Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/