Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Course
  • Reading Paths
  • Concept Map
  • How to Read the Diagrams
  • Part 0: What Is a Protocol?10
  • Part 1: Timing and Clocking11
  • Part 2: Encoding and Framing12
  • Part 3: Handshakes13
  • Part 4: Flow Control17
  • Part 5: Transactions19
  • Part 6: Concurrency and Performance17
  • Part 7: Ordering13
  • Part 8: Sharing and Arbitration12
  • Part 9: Deadlock and Liveness13
  • Part 10: Reliability and Recovery20
    • Error Models
    • Parity
    • Hamming Distance
    • CRC
    • ECC and SECDED
    • Forward Error Correction
    • Error Responses
    • Poison and Containment
    • ACK and NAK
    • Sequence Numbers
    • Replay Buffers
    • Go-Back-N or Selective Repeat
    • Idempotency and Safe Replay
    • Link-Level or End-to-End Protection
    • Error Classes and Reporting
    • Recovery and Degradation
    • Interface Protection and Safety
    • The Reliability Budget
    • Protocols Compared: Reliability and Recovery
    • Drills: Reliability and Recovery
  • Part 11: Bring-Up and Link Management10
  • Part 12: Power8
  • Part 13: Shared State and Coherence9
  • Part 14: Security and Isolation7
  • Part 15: Specifying and Verifying11
  • Part 16: Protocols Dissected17
  • Part 17: Capstones5
  • Part 18: Interview Preparation6
Loading lesson

‹Part 10: Reliability and Recovery
  1. Topics
  2. First Principles of Hardware Protocols
  3. Part 10: Reliability and Recovery
  4. Parity

Part 10 · Reliability and Recovery · Foundation (F)

Parity

One extra bit per word makes the count of 1s even (or odd). Parity detects any odd number of flipped bits, misses any even number, and costs almost nothing. Where that is enough, and where it is not.

On this page

    Note

    Level: Foundation (F) · Answers: What if bits go wrong?

    Before this: Error Models

    An on-chip register bus carries 32-bit words between blocks. Errors are extremely rare, but when one happens, the team wants to know rather than silently write a wrong value into a control register. A full error-correcting code would add seven or eight bits and a decoder to every port. One extra wire per bus, and one XOR tree at each end, catches most of what can realistically go wrong.

    What is the cheapest possible error detection, and what does it miss?

    The obvious answer, and why it breaks

    The obvious check is to send the data twice and compare. It catches everything except identical errors in both copies, and it doubles the wires. Most of that redundancy is wasted: to know that something changed, you need far less information than a full copy.

    The idea: one bit that records the count of 1s

    Even parity adds one bit chosen so the total number of 1s, data plus parity, is even. The receiver counts again (an XOR of all bits): if the result is odd, something changed. One flipped bit changes the count by one, so it is always detected. Two flipped bits change it by two (or zero), so the count is even again and the error is missed. In general, parity detects every odd number of flipped bits and misses every even number.

    Flipped bits

    Detected by parity?

    1

    Yes

    2

    No

    3

    Yes

    Any even number

    No

    Build it: a parity generator and checker

    The sender computes parity over 8 data bits; the channel flips one, two or three bits in different cycles; the receiver recomputes parity and flags a mismatch. The checker confirms parity's rule exactly.

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    // Even parity on an 8-bit bus. The sender adds a parity bit so that the nine bits
    // hold an even number of 1s; the receiver recomputes it and flags a mismatch. The
    // channel flips bits in some cycles: one bit (detected), two bits (missed), and
    // none. The checker confirms parity catches every odd number of flips and misses
    // every even number.
    module tb;
      logic clk = 0;
      always #5 clk = ~clk;
      initial begin $dumpfile("wave.vcd"); $dumpvars(0, tb); end
    
      int cyc = 0;
      always @(posedge clk) cyc <= cyc + 1;
    
      logic [7:0] data;
      logic [7:0] flip;                               // which bits the channel flips
      always_comb begin
        data = 8'h00; flip = 8'h00;
        case (cyc)
          1: begin data = 8'hA5; flip = 8'h00; end    // clean
          2: begin data = 8'hA5; flip = 8'h01; end    // one bit flipped
          3: begin data = 8'h3D; flip = 8'h00; end    // clean (five 1s: parity bit 1)
          4: begin data = 8'h3D; flip = 8'h81; end    // two bits flipped
          5: begin data = 8'hFF; flip = 8'h07; end    // three bits flipped
          default: ;
        endcase
      end
      wire       par   = ^data;                       // sender: even parity over the data
      wire [7:0] rx    = data ^ flip;                 // what arrives
      wire       err   = (^rx) ^ par;                 // receiver: recompute and compare
    
      int errors = 0;
      always @(posedge clk) if (cyc >= 1 && cyc <= 5) begin
        if (err != ($countones(flip) % 2 == 1)) errors++;
      end
      initial begin
        #80;
        if (errors == 0) $display("PASS: parity flagged the 1-bit and 3-bit errors and missed the 2-bit error, as expected");
        else $display("FAIL: %0d mismatches", errors);
        $finish;
      end
    endmodule

    Both ends are a single XOR reduction (^data): parity's whole hardware cost is one wire and two small XOR trees.

    Watch it run

    How to read it, slot by slot:

    • Slot 0: data 0xA5 (four 1s), parity 0, no flips: no error.

    • Slot 1: the channel flips bit 0 (flip 1). The receiver's count is now odd: err is 1.

    • Slots 2 and 3: data 0x3D has five 1s, so the parity bit is 1. In slot 3 the channel flips two bits (flip 0x81): the count is even again and err stays 0. The error is missed.

    • Slot 4: three bits flipped (flip 0x07) in 0xFF: an odd number, detected.

    Where parity is enough

    Use

    Why parity fits

    On-chip buses and register paths

    Errors are rare and almost always single bits; detection is enough to raise an alarm

    Cache tags and small memories, together with refetch

    A parity error on clean data can be fixed by reading it again from memory

    Control signals of an interface (lesson 10.17)

    Cheap protection for a few critical wires

    Serial lines such as UART (optional)

    One bit per character, at low speed

    Parity is not enough where bursts are common (fast serial links, where a CRC is used), where errors must be corrected rather than just detected (memories holding the only copy, where ECC is used), or where missing a double error is unacceptable.

    What breaks

    A design (illustrative) used one parity bit over a 64-bit bus whose wires ran side by side for several millimetres. Crosstalk occasionally flipped two neighbouring bits together, which parity cannot see. Splitting the bus into eight byte-wide parity groups, so neighbouring wires belong to different groups, made those double errors visible.

    Why this matters

    Senior lens. Parity is the right answer when errors are rare, mostly single, and detection is enough. Check the error model: if adjacent bits can fail together, interleave parity groups across the wires; if the data is the only copy, use ECC; if the channel is a fast serial link, use a CRC. And always decide what the system does when parity fires: an alarm nobody handles is not protection.

    Interview

    Asked: "What does parity miss?"

    Weak answer: Nothing important.

    Strong answer: Any even number of flipped bits. Parity records whether the count of 1s is even or odd, so one flip changes it and is caught, but two flips change it back and are invisible. It also can't say which bit is wrong, so it can't correct. That's fine for rare single-bit errors on chip, but not for bursts on serial links, where you use a CRC, or for stored data you must correct, where you use ECC. Interleaving parity groups across neighbouring wires helps against adjacent double flips.

    Follow-ups: (1) How would you protect a 64-bit bus against crosstalk with parity? (2) Why can parity on a cache tag still lead to correct behaviour?

    Check yourself Even parity over 0b1011_0010: what is the parity bit?

    Four 1s, already even: the parity bit is 0.

    Check yourself Why does splitting a bus into byte-wide parity groups help against crosstalk?

    Neighbouring wires that fail together then belong to different groups, so each group sees a single flip, which parity detects.

    Key takeaways

    • Parity adds one bit so the count of 1s is even; the receiver XORs everything to check.

    • It detects any odd number of flipped bits, misses any even number, and cannot correct.

    • Use it for rare single-bit errors on chip; use CRCs for bursts and ECC for data that must be corrected.

    Keep going

    Next: Lesson 10.3, Hamming Distance. Why the distance between code words decides what a code can detect and correct.

    Related topics

    • Part 10 overview: Reliability and Recovery

    Previous

    143 / 234

    Next: Hamming Distance

    Up next

    Up nextHamming Distance

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • CRC
    • ECC and SECDED
    • Forward Error Correction
    clkdataa53dff0flip0108170parerr
    Simulation output: parity flags the one-bit and three-bit errors and misses the two-bit error.