---
title: Problem set 4
heading: "Problem set 4: building blocks and arithmetic"
eyebrow: C7 · Problem set 4
type: problems
---

::: hook
These problems use lessons 16 to 21: decoders, encoders, multiplexers and comparators, arithmetic circuits and the ALU, propagation delay and glitches, shifters, multipliers and number formats, and division.
:::

::: pool
pick: 12

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

## A decoder has {n} inputs; it's to be built from 2-to-4 decoders with enables.

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

### How many outputs does it have?

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

::: part
answer: (4^(n/2) - 1)/3
tolerance: 0

### How many 2:4 decoders does a tree of them need?

::: misses
- [any] Each level decodes two more bits: 1 + 4 + 16 + ... decoders.
:::
:::
:::

::: check
kind: parts
given: N = 8 | 64 | 1024

## A multiplexer selects one of {N} inputs.

::: part
answer: log(N)/log(2)
tolerance: 0.1%

### How many select lines does it need?

::: misses
- [any] $\log_2 N$.
:::
:::

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

### How many 2:1 multiplexers make it as a tree?

::: misses
- [any] Each removes one candidate.
:::
:::
:::

::: check
kind: boolean
vars: I3, I2, I1, I0
answer: I3 | I2
ops: and, or, not

## A 4-input priority encoder has $I_3$ highest. Write its top output bit $Y_1$.

::: misses
- [any] $Y_1$ is 1 when the winner is input 3 or 2.
:::
:::

::: check
kind: boolean
vars: A1, A0, B1, B0
answer: ~A1 & B1 | ~(A1 ^ B1) & ~A0 & B0
ops: and, or, not, xor

## Write A < B for 2-bit numbers $A_1A_0$ and $B_1B_0$.

::: misses
- [any] The top bits decide unless they're equal.
:::
:::

::: check
given: a = 7 | 31 | 90; b = 40 | 100 | 127
answer: a - b + 256*step(b - a)
base: 2
width: 8

## Compute {a} − {b} in 8-bit two's complement and give the 8-bit result.

::: misses
- [any] Invert {b}, add 1, add {a}.
:::
:::

::: check
kind: parts
given: a = 60 | 100; b = 50 | 90

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

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

### What is the true sum?

::: misses
- [any] Add them.
:::
:::

::: part
answer: a + b - 256*step(a + b - 127.5)
tolerance: 0

### What value does the 8-bit result represent?

::: misses
- [any] If the sum exceeds 127, it wraps by 256.
:::
:::
:::

::: check
kind: parts
given: n = 16 | 32 | 64; tc = 2 | 3; tg = 3 | 4

## An adder's ripple carry takes {tc} gate delays per bit; a lookahead design reaches any carry in {tg} delays per lookahead level, with 4-bit groups.

::: part
answer: n*tc
tolerance: 0

### What is the ripple adder's worst carry delay for {n} bits?

::: misses
- [any] Every bit in the chain.
:::
:::

::: part
answer: tg*ceil(log(n)/log(4))
tolerance: 0.1%

### How many delays for the lookahead adder, with $\lceil\log_4 n\rceil$ levels?

::: misses
- [any] Levels times delays per level.
:::
:::
:::

::: check
kind: parts
given: na = 2 | 4; nx = 1 | 3; no = 1 | 2; ta = 20 | 35; tx = 40 | 60; to = 25 | 30

## A critical path passes through {na} AND gates ({ta} ps each), {nx} XOR gates ({tx} ps each) and {no} OR gates ({to} ps each).

::: part
answer: na*ta + nx*tx + no*to
unit: ps
tolerance: 0.5%

### What is its propagation delay?

::: misses
- [any] Add every gate's delay along the path.
:::
:::

::: part
answer: 1e3/(na*ta + nx*tx + no*to)
unit: GHz
tolerance: 0.5%

### Ignoring the flip-flops, what is the highest rate at which new results can be produced?

::: misses
- [any] One over the delay.
:::
:::
:::

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

## An {n} × {n} array multiplier.

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

### How many product bits?

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

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

### How many AND gates for the partial products?

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

::: check
given: x = -12 | -50 | -100; k = 2 | 3
answer: floor(x/2^k) + 256
base: 2
width: 8

## Arithmetically shift the 8-bit two's-complement number {x} right by {k} places. Give the 8-bit result.

::: misses
- [any] Copy the sign bit into the vacated places.
:::
:::

::: check
kind: parts
given: k = 25 | 100 | 200; n = 3 | 5

## A fixed-point format has {n} fraction bits.

::: part
answer: k/2^n
tolerance: 0.1%

### What value does the stored integer {k} represent?

::: misses
- [any] $k/2^n$.
:::
:::

::: part
answer: 2^(-n)
tolerance: 0.1%

### What is its resolution?

::: misses
- [any] $2^{-n}$.
:::
:::
:::

::: check
kind: parts
given: e = 124 | 127 | 133; f = 0 | 0.5 | 0.75

## An IEEE 754 single has sign 0, exponent field {e} and fraction {f} (as a binary fraction's value).

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

### What is its unbiased exponent?

::: misses
- [any] Subtract the bias, 127.
:::
:::

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

### What value does it represent?

::: misses
- [any] $1.f \times 2^{e - 127}$.
:::
:::
:::

::: check
kind: boolean
vars: I3, I2, I1, I0
answer: I3 | I2
ops: and, or, not

## A 4-input priority encoder (I3 highest) outputs $Y_1Y_0$. Write $Y_1$.

::: right
Right: $Y_1 = I_3 + I_2$, 1 whenever the winner is input 3 or 2.
:::

::: misses
- [any] Not yet. $Y_1$ is the top bit of the winning input's number.
:::
:::

::: check
kind: parts
given: s = 0 | 1; e = 126 | 131; f = 0.25 | 0.625

## A 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 does it hold?

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

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

### What's its unbiased exponent?

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

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

## An n-bit carry-select adder with n = {n} uses {k}-bit blocks (2 gate delays per bit within a block, 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*n
tolerance: 0.5%

### And a ripple adder's?

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

::: check
given: A = 0..15 int; B = 0..15 int
answer: A - B + 16 - 16*floor((A - B + 16)/16)
base: 2
width: 4

## A 4-bit ALU subtracts B = {B:bin4} from A = {A:bin4} by adding $\bar B$ and a carry-in of 1. What result does it produce?

::: right
Right: {answer}. The carry out tells you whether unsigned A ≥ B.
:::

::: misses
- [any] Not yet. Invert B, add A and 1, keep four bits.
:::
:::

::: check
given: N = 100 | 150 | 211 | 250; D = 6 | 7 | 11
answer: floor(N/D)

## A restoring divider computes {N} ÷ {D}, one quotient bit per step. What quotient does it produce?

::: right
Right: {answer}, after 8 steps for 8-bit operands.
:::

::: misses
- [any] Not yet. Truncate: $\lfloor N/D\rfloor$.
:::
:::
:::
