Convert a BCD digit to excess-3 and an excess-3 code word back to BCD. Flag every pattern that is not a code word.
Hardware context: The coin adder of a parking meter and the bridge between an excess-3 calculator and a BCD display. Convert between BCD and excess-3 both ways and flag the patterns that are not code words.
An old desk calculator keeps its digits in excess-3, because inverting a digit then gives its nines' complement. A new display board speaks BCD. The bridge between them must convert both ways and catch corrupted digits.
This is an Implement problem. Write xs3_convert. It encodes bcd_in into excess-3 and decodes x3_in back into BCD. The two halves work independently.
A BCD input above 1001 is not a digit, and an excess-3 input outside 0011 to 1100 is not a code word. For such an input, the output is 0000 and its flag is 1.
The check applies eight pairs of inputs, one per nanosecond, and records all four outputs after each.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
script | 64 | input of each check |
Full specification
module xs3_convert (
input logic [3:0] bcd_in, // a BCD digit to encode
input logic [3:0] x3_in, // an excess-3 code word to decode
output logic [3:0] x3_out, // the excess-3 code of bcd_in, or 0000
output logic bcd_bad, // 1 when bcd_in is not a BCD digit
output logic [3:0] bcd_out, // the BCD digit of x3_in, or 0000
output logic x3_bad // 1 when x3_in is not an excess-3 code word
);
// your design
endmodule
| Input | Valid patterns | Output when valid | Output when invalid |
|---|---|---|---|
| bcd_in | 0000 to 1001 | x3_out = the digit plus 3, bcd_bad = 0 | x3_out = 0000, bcd_bad = 1 |
| x3_in | 0011 to 1100 | bcd_out = the code word minus 3, x3_bad = 0 | bcd_out = 0000, x3_bad = 1 |
The result fields are x3_out, bcd_bad, bcd_out and x3_bad with the suffix _step0 for the first pair, up to _step7.
Examples
Example 1
Small Digits Both Ways- Input
bcd_in 0000, x3_in 0011; bcd_in 0001, x3_in 0100; bcd_in 0100, x3_in 0111; bcd_in 0010, x3_in 1100; bcd_in 1001, x3_in 0011; bcd_in 0101, x3_in 1000; bcd_in 0011, x3_in 0110; bcd_in 0111, x3_in 1010
- Output
x3_out_step0 = 'b0011, bcd_bad_step0 = no, bcd_out_step0 = 0, x3_bad_step0 = no, x3_out_step1 = 'b0100, bcd_bad_step1 = no, bcd_out_step1 = 1, x3_bad_step1 = no, x3_out_step2 = 'b0111, bcd_bad_step2 = no, bcd_out_step2 = 4, x3_bad_step2 = no, x3_out_step3 = 'b0101, bcd_bad_step3 = no, bcd_out_step3 = 9, x3_bad_step3 = no, x3_out_step4 = 'b1100, bcd_bad_step4 = no, bcd_out_step4 = 0, x3_bad_step4 = no, x3_out_step5 = 'b1000, bcd_bad_step5 = no, bcd_out_step5 = 5, x3_bad_step5 = no, x3_out_step6 = 'b0110, bcd_bad_step6 = no, bcd_out_step6 = 3, x3_bad_step6 = no, x3_out_step7 = 'b1010, bcd_bad_step7 = no, bcd_out_step7 = 7, x3_bad_step7 = no
The digit 0 encodes as 0011 and the code word 0011 decodes as 0. The digit 9 encodes as 1100. No input here is invalid, so both flags stay 0.
Example 2
Patterns That Are Not BCD Digits- Input
bcd_in 1010, x3_in 0011; bcd_in 1011, x3_in 0100; bcd_in 1100, x3_in 0101; bcd_in 1101, x3_in 0110; bcd_in 1110, x3_in 0111; bcd_in 1111, x3_in 1000; bcd_in 1010, x3_in 1001; bcd_in 1111, x3_in 1100
- Output
x3_out_step0 = 'b0000, bcd_bad_step0 = yes, bcd_out_step0 = 0, x3_bad_step0 = no, x3_out_step1 = 'b0000, bcd_bad_step1 = yes, bcd_out_step1 = 1, x3_bad_step1 = no, x3_out_step2 = 'b0000, bcd_bad_step2 = yes, bcd_out_step2 = 2, x3_bad_step2 = no, x3_out_step3 = 'b0000, bcd_bad_step3 = yes, bcd_out_step3 = 3, x3_bad_step3 = no, x3_out_step4 = 'b0000, bcd_bad_step4 = yes, bcd_out_step4 = 4, x3_bad_step4 = no, x3_out_step5 = 'b0000, bcd_bad_step5 = yes, bcd_out_step5 = 5, x3_bad_step5 = no, x3_out_step6 = 'b0000, bcd_bad_step6 = yes, bcd_out_step6 = 6, x3_bad_step6 = no, x3_out_step7 = 'b0000, bcd_bad_step7 = yes, bcd_out_step7 = 9, x3_bad_step7 = no
Every bcd_in here is above 1001, so x3_out is 0000 and bcd_bad is 1 in every step. The x3_in side is valid and decodes normally.
Example 3
Every Digit Encoded- Input
bcd_in 0000, x3_in 0101; bcd_in 0001, x3_in 0101; bcd_in 0010, x3_in 0101; bcd_in 0011, x3_in 0101; bcd_in 0100, x3_in 0101; bcd_in 0101, x3_in 0101; bcd_in 0110, x3_in 0101; bcd_in 0111, x3_in 0101
- Output
x3_out_step0 = 'b0011, bcd_bad_step0 = no, bcd_out_step0 = 2, x3_bad_step0 = no, x3_out_step1 = 'b0100, bcd_bad_step1 = no, bcd_out_step1 = 2, x3_bad_step1 = no, x3_out_step2 = 'b0101, bcd_bad_step2 = no, bcd_out_step2 = 2, x3_bad_step2 = no, x3_out_step3 = 'b0110, bcd_bad_step3 = no, bcd_out_step3 = 2, x3_bad_step3 = no, x3_out_step4 = 'b0111, bcd_bad_step4 = no, bcd_out_step4 = 2, x3_bad_step4 = no, x3_out_step5 = 'b1000, bcd_bad_step5 = no, bcd_out_step5 = 2, x3_bad_step5 = no, x3_out_step6 = 'b1001, bcd_bad_step6 = no, bcd_out_step6 = 2, x3_bad_step6 = no, x3_out_step7 = 'b1010, bcd_bad_step7 = no, bcd_out_step7 = 2, x3_bad_step7 = no
The digits 0 to 7 encode as 0011 to 1010, three above each digit. x3_in is 0101 in every step, which decodes as 2.
Constraints and Contract
- Inputs are known 0/1 values. Each pair is held for one nanosecond and the outputs are sampled at its end.
- Keep the module name and the ports. The design is combinational.
Hints
Hint 1
Excess-3 stores each digit plus 3. A 4-bit adder with the constant 3 encodes, and a subtractor decodes.
Hint 2
Write the flags first. The valid code words of excess-3 are the ten values from 3 to 12.
Hint 3
Use each flag to choose between the converted value and 0000.
What the grader checks: Seven directed and eight seeded cases of eight steps each run on the block. All four outputs are compared after every step with a model written in JavaScript.
15 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone