---
title: Problem set 5
heading: "Problem set 5: arithmetic, formats and simulation"
eyebrow: C7 · Problem set 5
type: problems
---

::: hook
These problems use lessons 16 to 24: building blocks, arithmetic circuits, delay and glitches, multipliers and number formats, and the number formats and gate simulation labs.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 90 | 110 | 125; b = 50 | 70

## The 8-bit two's-complement numbers {a} and {b} are added.

::: part
answer: a + b - 256
tolerance: 0

### What signed value results?

::: misses
- [a + b] Above 127 the result wraps by 256.
- [any] Subtract 256.
:::
:::

::: part
answer: 1
tolerance: 0

### What's the overflow flag?

::: misses
- [0] Two positives gave a negative.
- [any] V is set.
:::
:::
:::

::: check
kind: parts
given: s = 0 | 1; e = 124 | 129 | 140; f = 0.125 | 0.5 | 0.75

## A single-precision float has sign {s}, biased exponent {e} and fraction {f}.

::: part
answer: (1 - 2*s)*(1 + f)*2^(e - 127)
tolerance: 0.001%

### What value is it?

::: misses
- [any] $(-1)^s(1 + f)2^{e - 127}$.
:::
:::

::: part
answer: 2^(e - 150)
tolerance: 0.001%

### What's the spacing to the next float?

::: misses
- [any] $2^{e - 127 - 23}$.
:::
:::
:::

::: check
kind: parts
given: a = 0.25 | 0.5 | 0.75; b = 0.125 | 0.5 | 0.875

## Two Q15 values represent {a} and {b}.

::: part
answer: a*32768
tolerance: 0

### What integer stores {a}?

::: misses
- [any] $a \times 2^{15}$.
:::
:::

::: part
answer: a*b*32768
tolerance: 0

### What integer stores their product, rounded?

::: misses
- [a*b*32768*32768] Shift the 30-fraction-bit product right by 15.
- [any] $ab \times 2^{15}$.
:::
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 32; t = 20 | 50; r = 30 | 60

## An n-bit ripple adder with n = {n} has {t} ps of gate delay, with 2 gates per bit, between registers with {r} ps of overhead.

::: part
answer: 2*n*t
unit: ps
tolerance: 0.5%

### What's its worst delay?

::: misses
- [any] $2nt$.
:::
:::

::: part
answer: 1000/(2*n*t + r)
unit: GHz
tolerance: 0.5%

### What's the fastest clock?

::: misses
- [any] $\frac{1}{2nt + t_\text{reg}}$.
:::
:::
:::

::: check
kind: parts
given: n = 16 | 32 | 64; k = 2 | 4 | 8

## An n-bit carry-select adder with n = {n} uses blocks of k = {k} bits: 2 gate delays per bit inside a block and 2 per block for the selects.

::: part
answer: 2*k + 2*n/k
tolerance: 0.5%

### What's its delay, in gate delays?

::: misses
- [any] $2k + \frac{2n}{k}$.
:::
:::

::: part
answer: 2*sqrt(n) + 2*n/sqrt(n)
tolerance: 0.5%

### What would the best block size, $\sqrt n$, give?

::: misses
- [any] $4\sqrt n$.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8 | 16

## An n × n array multiplier with n = {n} uses one full adder per partial-product bit after the first row.

::: part
answer: n*(n - 1)
tolerance: 0

### About how many full adders?

::: misses
- [n*n] The first row needs no adding.
- [any] $n(n - 1)$.
:::
:::

::: part
answer: 2*n
tolerance: 0

### How many bits wide is the product?

::: misses
- [any] $2n$.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8; v = 3 | 5 | 9 | 13

## Gray code with {n} bits.

::: part
answer: 8*floor(v/8) + 4*(floor(v/4) + floor(v/8) - 2*floor((floor(v/4) + floor(v/8))/2)) + 2*(floor(v/2) + floor(v/4) - 2*floor((floor(v/2) + floor(v/4))/2)) + (v + floor(v/2) - 2*floor((v + floor(v/2))/2))
tolerance: 0

### What's the Gray code of {v}, as a number?

::: misses
- [any] $v \oplus (v \gg 1)$.
:::
:::

::: part
answer: 2^n
tolerance: 0

### How many steps does an n-bit Gray counter take to return to 0?

::: misses
- [any] $2^n$, like binary.
:::
:::
:::

::: check
kind: parts
given: k = 8 | 16 | 32 | 64

## SECDED memory protects {k}-bit words with Hamming check bits plus one overall parity bit.

::: part
answer: ceil(log(k + 1 + ceil(log(k + 1)/log(2)))/log(2)) + 1
tolerance: 0

### How many check bits per word?

::: misses
- [ceil(log(k + 1 + ceil(log(k + 1)/log(2)))/log(2))] Add the overall parity bit for double-error detection.
- [any] Hamming's r plus 1.
:::
:::

::: part
answer: (ceil(log(k + 1 + ceil(log(k + 1)/log(2)))/log(2)) + 1)/k*100
unit: %
tolerance: 0.5%

### What's the storage overhead?

::: misses
- [any] Check bits over data bits.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 16 | 64; t = 30 | 80

## A 1-of-N multiplexer is built as a tree of 2:1 multiplexers, each with {t} ps of delay, N = {N}.

::: part
answer: log(N)/log(2)
tolerance: 0

### How many levels deep is it?

::: misses
- [any] $\log_2N$.
:::
:::

::: part
answer: N - 1
tolerance: 0

### How many 2:1 multiplexers does it use?

::: misses
- [N/2] Count every level.
- [any] $N - 1$.
:::
:::
:::

::: check
kind: boolean
vars: A, B, Cin
answer: A & B | Cin & (A ^ B)
ops: and, or, xor

## Write a full adder's carry out using AND, OR and XOR.

::: right
Right: $AB + C_\text{in}(A \oplus B)$, generate or propagate.
:::

::: misses
- [any] Not yet. It carries when both inputs are 1, or when exactly one is and a carry comes in.
:::
:::

::: check
kind: boolean
vars: A, B, Cin
answer: A ^ B ^ Cin
ops: xor

## Write a full adder's sum.

::: right
Right: $A \oplus B \oplus C_\text{in}$.
:::

::: misses
- [any] Not yet. The sum is 1 when an odd number of inputs are 1.
:::
:::

::: check
kind: parts
given: d1 = 1 | 2; d2 = 2 | 3; d3 = 1 | 4

## A path through three gates has delays of {d1}, {d2} and {d3} units, and a second path from the same input reaches the same output gate through one gate of 1 unit.

::: part
answer: d1 + d2 + d3
tolerance: 0

### When does the long path's change arrive?

::: misses
- [any] The sum of its delays.
:::
:::

::: part
answer: d1 + d2 + d3 - 1
tolerance: 0

### How long can the output glitch last, at most?

::: misses
- [any] The difference between the paths' arrivals.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8 | 12

## A ripple-carry adder is built from two-input gates as in the gate simulation lab, for n = {n}.

::: part
answer: 2*n + 1
tolerance: 0

### How deep is its carry-out?

::: misses
- [any] $2n + 1$.
:::
:::

::: part
answer: 5*n
tolerance: 0

### How many gates does it use?

::: misses
- [any] Two XORs, two ANDs and an OR per bit.
:::
:::
:::

::: check
kind: parts
given: e = 120 | 130; f = 0.3 | 0.7

## A float has biased exponent {e}; its fraction field is about {f}.

::: part
answer: e - 127
tolerance: 0

### What power of two scales it?

::: misses
- [any] $e - 127$.
:::
:::

::: part
answer: 2^(-23)
tolerance: 0.001%

### What's its relative precision, the spacing over the leading power of two?

::: misses
- [any] $2^{-23}$ for every normal float.
:::
:::
:::

::: check
kind: parts
given: a = 3 | 7 | 11; b = 5 | 6 | 13

## A 4-bit shift-and-add multiplier computes {a} × {b}.

::: part
answer: a*b
tolerance: 0

### What's the product?

::: misses
- [any] $a \times b$.
:::
:::

::: part
answer: floor(b/8) + floor(b/4) - 2*floor(b/8) + floor(b/2) - 2*floor(b/4) + b - 2*floor(b/2)
tolerance: 0

### How many additions does it perform (one per 1 bit of the multiplier {b})?

::: misses
- [any] Count the 1 bits of b.
:::
:::
:::
:::
