Tasks Overall Requirements Write two programs encode.toy and decode.toy. Each TOY instruction must have corresponding pseudocode. (This is auto-generated by Visual X-Toy – see below.) It's also good practice to add line breaks between logically related "sections" of TOY code and write a comment above each "section" explaining what that code does. encode.toy
Implementation Tasks
Overall Requirements
- Write two programs encode.toy and decode.toy.
- Each TOY instruction must have corresponding pseudocode. (This is auto-generated by Visual X-Toy – see below.) It's also good practice to add line breaks between logically related "sections" of TOY code and write a comment above each "section" explaining what that code does.
encode.toy
Write a TOY
- p1 = m1 ^ m2 ^ m4
- p2 = m1 ^ m3 ^ m4
- p3 = m2 ^ m3 ^ m4
Recall that ^ is the exclusive or operator in Java and TOY. This captures the parity concept described above.
decode.toy
Write a TOY program decode.toy to decode and correct a Hamming encoded message. Repeatedly read seven (7) bits m1, m2, m3, m4, p1, p2, p3 from TOY standard input and write the four (4) correct bits m1, m2, m3, m4 to TOY standard output. Stop upon reading FFFF from standard input. Recall, to determine which one, if any, of the message bits is corrupted, perform the parity checks:
- p1 = m1 ^ m2 ^ m4
- p2 = m1 ^ m3 ^ m4
- p3 = m2 ^ m3 ^ m4
Compare the parity bits you computed with the parity bits you received. If they don't match, then some bit was flipped. Here's what to do with the results:
- If exactly zero or one of the parity checks fail, then all four message bits are correct.
- If checks 1 and 2 fail (but not check 3), then bit m1 is incorrect.
- If checks 1 and 3 fail (but not check 2), then bit m2 is incorrect.
- If checks 2 and 3 fail (but not check 1), then bit m3 is incorrect.
- If all three checks fail, then bit m4 is incorrect.
Flip the corrupted message bit (if necessary) and write (only) m1, m2, m3, m4 to standard output.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps