All problems
Hamming (7,4) Payload Bits
Problem
Correct at most one bit error in a received Hamming (7,4) word and return the four data bits. Positions 1 through 7 hold p1, p2, d1, p4, d2, d3, d4; the syndrome is the XOR of the 1-based positions of the set bits, and a nonzero syndrome flips that position. Return the data bits in order d1, d2, d3, d4.
Hint
Compute the syndrome from the parity positions, fix the indicated bit, then read positions 3, 5, 6, and 7.
Test cases
case 1
in: [[0,1,1,0,0,1,1]]
expected: [1,0,1,1]
case 2
in: [[0,1,1,0,1,1,1]]
expected: [1,0,1,1]
case 3
in: [[1,1,1,1,1,1,1]]
expected: [1,1,1,1]
case 4
in: [[0,0,0,0,0,0,0]]
expected: [0,0,0,0]
case 5
in: [[0,0,1,0,0,1,1]]
expected: [1,0,1,1]
Starter codePython
def hamming74_payload(received):
# Your code here
pass5 test cases · run your code against them in the editor