Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-091

Hamming (7,4) Encode

Problem

Encode 4 data bits into a systematic Hamming(7,4) codeword with the data bits at positions 3, 5, 6 and 7 using 1-indexed positions. With data = [d1, d2, d3, d4] compute p1 = d1^d2^d4, p2 = d1^d3^d4 and p4 = d2^d3^d4, then return the codeword [p1, p2, d1, p4, d2, d3, d4].

Hint

Each parity bit covers the data positions that have its index bit set.

Test cases

case 1
in: [[0,0,0,0]]
expected: [0,0,0,0,0,0,0]
case 2
in: [[1,0,0,0]]
expected: [1,1,1,0,0,0,0]
case 3
in: [[0,1,0,0]]
expected: [1,0,0,1,1,0,0]
case 4
in: [[1,1,1,1]]
expected: [1,1,1,1,1,1,1]
Starter codePython
def hamming74_encode(data):
    # Your code here
    pass

4 test cases · run your code against them in the editor