Practice
Cave Radio Mend
A cave rescue team 400 m inside a mountain has one link to the surface: a cave radio that sends data through the rock. The signal is very weak, and a farm pump farther up the valley causes interference across the radio band that flips some bits. Two rescues ago, a flipped bit turned a water-level report into a code nobody had defined. The surface controller spent 20 minutes asking for repeats.
The underground transmitter is sealed in epoxy, so its half of the job cannot change. It wraps every 8-bit word in a 13-bit frame. Number the frame bits 0 to 12:
- Bits 1, 2, 4 and 8 are check bits. The encoder sets each one so that its group holds an even number of ones.
- Bit 1's group is frame bits 1, 3, 5, 7, 9, 11. Bit 2's group is 2, 3, 6, 7, 10, 11.
- Bit 4's group is 4, 5, 6, 7, 12. Bit 8's group is 8, 9, 10, 11, 12.
- Bit 0 is set last, so that the whole 13-bit frame carries an even number of ones.
- The payload sits in the remaining positions:
data(0)at frame bit 3, thendata(1)throughdata(7)at bits 5, 6, 7, 9, 10, 11, 12.
Your task: build the surface receiver. A frame with 1 flipped bit anywhere (payload, check bit, or bit 0 itself) must come out repaired. A frame with 2 flipped bits must be flagged and passed through untouched. A guessed correction would flip a 3rd bit and hand the controller a confidently wrong word. A damaged frame gets exactly one of two verdicts: repaired, or flagged unusable.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
code | in | 13-bit vector | Received frame, bit numbering as described above |
data | out | 8-bit vector | Payload, corrected when possible |
single | out | 1 bit | One flip found and repaired, payload is trustworthy |
double | out | 1 bit | Two flips found, payload passed through raw |
Behavior
- Recompute the 4 group parities over the received frame. The 4 results form a 4-bit syndrome, bit 1's group in the lowest position up to bit 8's group in the highest
- Also recompute the overall parity across all 13 bits
- Clean frame, syndrome zero and overall parity even:
datais the payload as received,single = 0,double = 0 - Odd overall parity means exactly one bit flipped (the code assumes at most 2 flips per frame):
single = 1,double = 0 - In that case the syndrome value is the frame position of the flipped bit; undo that flip before extracting the payload
- A syndrome of zero with odd overall parity means frame bit 0 itself flipped
- A syndrome naming a check bit position (1, 2, 4 or 8) means that check bit flipped
- In both of those cases the payload is already clean and passes through as received, still with
single = 1 - Even overall parity with a nonzero syndrome means two bits flipped:
double = 1,single = 0 - When
double = 1,datacarries the payload bits of the received frame exactly as they arrived, with no correction applied
What the bench checks
- Six clean frames must pass unchanged with both error flags low
- Every one of the 13 single-bit positions is flipped on three words; the data must be corrected and only
singleraised - All 78 double flips on one word, plus eight structural cases on two others, must raise only
doubleand pass the received payload through
Constraints
purely combinational: the outputs settle from code alone, with no clock and no state.
this models the surface decoder for one received 13-bit frame. The sealed transmitter, the radio link, and frames with more than two flipped bits are out of scope.
purely combinational. The outputs are functions of code alone, with no clock and no state.
when double is high the payload must pass through exactly as received, correction logic disarmed.
Do not add ports.
Click Run to execute your code. Output will appear here.