Tech

Digital design and FPGAs

Reason about hardware the way trading-latency teams do: bits and fixed point, logic and registers, clock limits and pipelines, signals crossing clock domains, and when an FPGA (field-programmable gate array) beats a CPU (central processing unit).

Read first: Computer architecture and GPUs

7 concepts8 min read25-question test, from a bank of 33Updated

Concept 1 of 71 min

Binary arithmetic: two's complement, fixed point, bits and ECC

The rule
In two's complement a negative number is read by inverting the bits and adding 1, and n bits cover −2n−1 to 2n−1 − 1.
Worked examples

Reading a negative byte

Given
Bits11111011
  1. Invert: 00000100, which is 4
  2. Add 1: 4 + 1 = 5
  3. So 11111011 is −5

Two's complement reads a negative by inverting and adding 1.

An 8-bit overflow

Given
Range−128 to 127
Values100 and 100
Values in 8 bits256
  1. True sum = 100 + 100 = 200
  2. Wraps to 200 − 256 = −56

Without saturation, the sum silently changes sign.

A fixed-point product

Given
FormatQ8.8
Fractional bits8
  1. Product bits = 8 + 8 = 16 fractional
  2. Shift right by 8 to return

After a fixed-point product, shift back by the fractional bits.

The picture
Formula
Signed range=−2n−1 to 2n−1−1
wrapped value=true value−2ⁿ
Qm.f resolution=1/2f
fractional bits of a product=f₁+f₂
Why it holds

An overflow wraps by 2ⁿ. A fixed-point number with f fractional bits steps by 1/2f and a product's fractional bits add, a left shift drops the top bit of a fixed-width register, and ECC (error-correcting code) memory corrects single-bit errors.

Two's complement has one zero, so 8 bits give 128 negative values, zero and 127 positive ones; sign-and-magnitude wastes a pattern on −0. Wrapping is the default; saturating at the limit is common in signal processors but must be asked for.

After multiplying 2 fixed-point numbers, shift right by the fractional bits to return to the format, watching the integer part for overflow.

AND keeps bits set in both, OR in either, XOR (exclusive OR) in exactly one. ECC adds check bits that correct single-bit errors and detect double ones, which matters at scale and for long-running jobs. 8 bits cover −128 to 127 and 16 bits −32,768 to 32,767.

Watch out
  • Reading a negative pattern as unsigned.
  • Expecting overflow to stop at the maximum.
  • Forgetting that fractional bits add in a product.
In the interview
  1. A hardware team wants to process prices in fixed point instead of floating point. What would you ask before agreeing?

    A complete answer covers

    • What range and precision prices need: the integer and fractional bits.
    • How products and sums are rescaled and rounded.
    • What happens on overflow: wrap, saturate or flag.
    • How results are checked against a floating-point reference.

Also in our technical interviews, on camera, with a score.

Concept 2 of 71 min

Boolean logic and state machines

The rule
Boolean expressions simplify by factoring, so A·B + A·B' = A, and NAND (NOT AND) alone can build any gate.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 3 of 71 min

Registers in Verilog: assignments, latches and loops

The rule
In a clocked Verilog block, registers use non-blocking <=, which reads all old values before updating them together, so a <= b; b <= a swaps them.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 4 of 71 min

Clock limits, pipelining, power and bandwidth

The rule
The clock period must cover the longest path between registers plus setup and clock-to-output times.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 5 of 71 min

Crossing clock domains and releasing resets

The rule
A signal from another clock domain can make a register metastable, so a single bit passes through a two-flop synchroniser.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 6 of 71 min

FPGAs: look-up tables, ASICs and trading

The rule
An FPGA builds logic from look-up tables, each a small memory whose 2k bits hold the truth table of any k-input function.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 7 of 71 min

AdvancedHow wide an accumulator must be

The rule
A product of an a-bit and a b-bit number needs a + b bits, and a sum of N values adds log₂ N bits, rounded up.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Recap

  • Two's complement: invert and add 1; n bits cover −2n−1 to 2n−1 − 1 and overflow wraps by 2ⁿ.
  • Fixed point Qm.n steps by 1/2ⁿ; fractional bits add when you multiply.
  • Maximum clock = 1/(longest path + register overheads); pipelining raises the clock and adds latency.
  • A signal from another clock domain needs a 2-flop synchroniser; a multi-bit value needs Gray code or a FIFO (first in, first out).
  • In clocked Verilog use <=; cover every branch or get a latch; an FPGA trades unit cost for no mask cost and deterministic speed.
Now test it

25 questions on Digital design and FPGAs

Timed, like the real one, drawn from a bank of 33. Every answer explained.

Test yourself →