Fundamentals — Diagnostic Tests
Unit Tests
UT-1: Two's Complement and Arithmetic
Question: (a) Convert to 8-bit two's complement. (b) Perform the addition using 8-bit two's complement binary. State whether overflow occurs. (c) What is the range of integers representable in 8-bit two's complement?
Solution:
(a) . Flip bits: . Add 1: .
in 8-bit two's complement .
(b) .
is a negative number (MSB ). Convert to decimal: flip bits , add 1 . So the result is .
Check: . Correct.
Overflow: No overflow occurs because a positive and negative number are being added, which can never produce overflow in two's complement. Overflow can only occur when adding two numbers of the same sign.
(c) Range: to . For : to .
UT-2: Floating Point Representation
Question: A floating-point system uses 8 bits: 1 sign bit, 3 exponent bits (excess-4), and 4 mantissa bits. Represent in this format. Calculate the absolute error and the relative error as a percentage.
Solution:
.
Normalise: .
Sign bit: (negative).
Exponent: in excess-4 .
Mantissa (4 bits after the implicit leading 1): .
Representation: .
Stored value: .
Absolute error: . The representation is exact in this case.
Relative error: .
For comparison, with only 3 mantissa bits:
Mantissa would be , stored value .
Absolute error . Relative error .
With 4 mantissa bits, is represented exactly because which fits in the available bits.
UT-3: Boolean Algebra Simplification
Question: Simplify the Boolean expression . Use Boolean algebra laws and verify with a Karnaugh map. Draw the logic circuit for the simplified expression using only NAND gates.
Solution:
Group .
Group .
So far: .
Simplify .
Therefore: .
Karnaugh map verification (minterms: , , , ):
| AB\C | 0 | 1 |
|---|---|---|
| 00 | 0 | 0 |
| 01 | 0 | 1 |
| 11 | 1 | 1 |
| 10 | 1 | 1 |
Groups:
- (column C=1, B=1):
- (row AB=11, A=1, B=1):
- (column C=1, A=1):
All three groups are essential prime implicants. , confirming the algebraic result.
NAND-only implementation: .
Each AND becomes NAND followed by NAND (as inverter). Each OR becomes NAND.
Using De Morgan's: .
This uses three NAND gates for the AND operations (actually, we can use NAND directly since ), and one NAND gate for the final OR (since ). Total: 4 NAND gates.
Integration Tests
IT-1: Number Systems and Data Representation (with Data Representation in Programming)
Question: The 16-bit two's complement number is stored in memory at address . (a) What decimal value does it represent? (b) If this represents the count of characters in a UTF-8 encoded string, how many bytes of memory does the string occupy? (c) If the string contains only ASCII characters, what is the maximum possible length of the string in characters?
Solution:
(a) : This is negative (MSB ).
Flip: . Add 1: .
So the value is .
A negative value is not a valid character count. The interpretation depends on whether the stored value is treated as signed or unsigned.
As unsigned: .
As signed 16-bit two's complement: .
If treated as signed, is not a valid count. If interpreted as unsigned: .
(b) If interpreted as unsigned ( characters) in UTF-8:
- ASCII characters: 1 byte each
- Extended Latin: 2 bytes
- Other scripts: 3 bytes
- Emoji: 4 bytes
Without knowing the character mix, we cannot determine the exact byte count. If all ASCII: bytes. If all 4-byte: bytes.
(c) Maximum ASCII characters in a string that occupies this many bytes: characters (if unsigned). If the value is , there is no valid interpretation as a character count.
This question illustrates the importance of choosing the correct representation: using an unsigned integer for counts avoids the confusion of negative values, while two's complement is essential for values that can be negative.
IT-2: Floating Point and Error Propagation (with Measurement/Scientific)
Question: A 12-bit floating-point system (1 sign, 5 exponent excess-15, 6 mantissa) stores the value . Calculate: (a) the stored binary representation, (b) the decimal value actually stored, (c) the absolute and relative error. (d) If 0.1 is added to itself 10 times using this representation, what is the accumulated error?
Solution:
(a) in binary: (repeating).
Normalised: .
Exponent: in excess-15 .
Mantissa (6 bits): (truncated after the implicit 1).
Sign: (positive).
Stored: .
(b) Actual stored value: .
.
.
(c) Absolute error: .
Relative error: .
(d) Adding 0.1 (stored as 0.099609375) ten times:
.
Expected: .
Accumulated error: .
Note: the error does NOT grow by a factor of 10 -- it stays at because we are adding the same truncated value repeatedly. In practice, floating-point addition at each step introduces additional rounding errors, so the actual accumulated error would be slightly different.
IT-3: Boolean Algebra and Logic Gates (with Computer Architecture)
Question: A half-adder adds two 1-bit numbers and produces a sum and carry. (a) Derive the Boolean expressions for sum () and carry (). (b) Show how two half-adders and an OR gate can be combined to create a full-adder. (c) For a 4-bit ripple-carry adder, calculate the maximum propagation delay if each half-adder has a delay of and each OR gate has a delay of .
Solution:
(a) Half-adder truth table:
| A | B | S | C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
(XOR). (AND).
(b) Full adder from two half-adders:
First half-adder: inputs , . Produces and . Second half-adder: inputs , . Produces and . OR gate: .
(c) For a 4-bit ripple-carry adder: each full-adder must wait for the carry from the previous stage.
Each full-adder uses 2 half-adders (5 ns each) and 1 OR gate (3 ns). But the critical path is the carry propagation.
Stage 1: , so and . Carry out is ready after the first half-adder produces , i.e., 5 ns.
For subsequent stages: the carry-in must propagate through. The longest path for carry:
- HA1 in stage : 5 ns to produce (needed for ).
- HA2 in stage : 5 ns to produce .
- OR gate: 3 ns for .
- Total per stage: ns.
For 4 stages: (first stage) .
Maximum propagation delay: .