id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

frew@mclean.com > hammingDecode
prev  |  next  |  chance

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)

public String hammingDecode(int m1, int m2, int m3, int m4, int p1, int p2, int p3) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy