about | help | code help+videos | done | prefs |
Write a method hammingDecode to correct a Hamming encoded message. Read 7 bits m1, m2, m3, m4, p1, p2, p3 in that order (not the Hamming order) and return 4 bits as a String. To determine which one, if any, of the message bits is corrupted, perform the parity checks. Compare the parity bits you computed with the parity bits you received. If they don't match, then some bit got flipped. Here's a summary of 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 m 1 is incorrect. If checks 1 and 3 fail (but not check 2), then bit m 2 is incorrect. If checks 2 and 3 fail (but not check 1), then bit m 3 is incorrect. If all three checks fail, then bit m 4 is incorrect. Flip the corrupted message bit (if necessary) and return m 1, m 2, m 3, and m 4 as a String. hammingDecode(1, 0, 0, 1, 1, 0, 0) → "1101" hammingDecode(1, 1, 0, 0, 1, 1, 0) → "1000" hammingDecode(1, 0, 1, 0, 1, 0, 1) → "1010" ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 200
Copyright Nick Parlante 2017 - privacy