For m data bits, choose r Hamming check bits such that 2^r >= m + r + 1, then add one overall parity bit for SECDED.
For the 32-bit SRAM, six Hamming check bits satisfy the inequality and one overall parity bit produces a 39-bit protected word. Numbering and coverage must be frozen in an encoder/decoder package so storage, injection, syndrome reporting, and verification use the same layout.
Use even parity, Hamming positions 1..7, and overall parity at position 8. Put p1/p2/p4 at 1/2/4; put d0/d1/d2/d3 at 3/5/6/7. Position numbers are not SystemVerilog bit indices: a packed vector [7:0] stores position j at bit j-1.
Read each check row across: it XORs only the bits shown in it. Position k is in check s_j when bit j of the number k is 1.
Clean word: every check row holds an even number of ones (four in s0, two in s1 and s2, four overall), so each XOR is 0.
One flip: flip position 5 and rows s0 and s2 each gain an odd count. The syndrome s2 s1 s0 = 101 = 5 points at the flipped position.
Overall row: it decides single versus double. One flip makes it odd; two flips leave it even with a nonzero syndrome, which is a detected UE.
// snippet: combinational equations for the frozen (8,4) convention
// c[1:7] are positional bits here; c[8] is overall parity.
c[3] = d[0]; c[5] = d[1]; c[6] = d[2]; c[7] = d[3];
c[1] = c[3] ^ c[5] ^ c[7];
c[2] = c[3] ^ c[6] ^ c[7];
c[4] = c[5] ^ c[6] ^ c[7];
c[8] = c[1] ^ c[2] ^ c[3] ^ c[4] ^ c[5] ^ c[6] ^ c[7];
// Compute these checks from received bits, not regenerated data parity.
s[0] = r[1] ^ r[3] ^ r[5] ^ r[7];
s[1] = r[2] ^ r[3] ^ r[6] ^ r[7];
s[2] = r[4] ^ r[5] ^ r[6] ^ r[7];
overall_bad = r[1] ^ r[2] ^ r[3] ^ r[4] ^ r[5] ^ r[6] ^ r[7] ^ r[8];Illustrative input/fault | Positions 1..8 / checks | Decode |
|---|---|---|
d[3:0]=1011 | 1,0,1,0,1,0,1,0; s=000, overall_bad=0 | Codeword clean |
Flip position 5 (d1) | Coverage checks 1 and 4 fail: s=101=5; overall_bad=1 | Flip received position 5 back, recover 1011 |
Flip position 8 only | s=000; overall_bad=1 | Repair overall bit; data unchanged |
Flip positions 3 and 5 | s=3 XOR 5=6; overall_bad=0 | UE; do not flip position 6 |
The calculator starts on the figure's word: d[3:0] = 1011, stored as 1 0 1 0 1 0 1 0 with nothing flipped. Click a received position to flip it and watch the check rows, the syndrome and the overall parity.
Loading secded calculator…
Flip position 5 (d1): rows s0 and s2 turn odd, the syndrome is 101 = 5 and overall parity is odd, so the decoder flips position 5 back and returns 1011.
Flip position 3 as well: the syndrome becomes 110 = 6 with even overall parity, a double-bit error. No data is returned and position 6 is left alone.
Clear, then flip positions 1, 2 and 3: the syndrome is 0 with odd overall parity, so the decoder calls it an overall-bit error and returns 1010 with d0 wrong. Three flips are outside the at-most-two-bit model.
For 39 bits, use Hamming positions 1..38 with parity at 1,2,4,8,16,32; place the 32 data bits in remaining positions in ascending order, then overall parity at 39. Each check k XORs received positions whose binary position has bit k set. Encoding sets each parity bit to XOR of the other positions it covers; overall parity XORs positions 1..38. An odd-parity nonzero syndrome beyond position 38 must be rejected as UE, never used as an array index.
The classification table assumes at most two flipped bits per codeword between trusted writes/repairs. It reports decoder classes under that model, not measured physical fault count. For example flips at positions 1,2,3 yield syndrome 1 XOR 2 XOR 3=0 with odd overall parity, aliasing the overall-parity-only CE row even though d0 is corrupt. Four flips at 1,2,4,7 have zero syndrome and even parity, aliasing clean. Higher-weight and correlated faults need a separate protection/risk analysis.
Syndrome | Overall parity mismatch | Meaning | Action |
|---|---|---|---|
0 | 0 | No error | Return data |
nonzero | 1 | Single-bit error in Hamming codeword | Correct indexed bit |
0 | 1 | Overall parity bit error | Data already correct |
nonzero | 0 | Double-bit error | Detect, do not correct |
Under the at-most-two-bit model, the overall parity bit flipped and data is unchanged (CE). Outside that model, positions 1/2/3 can alias the same row with corrupt data; the label does not prove the actual fault count.