PParityOchre
Workflows

Coding workflows · Hamming single-bit correction

03
Built around your work

A concrete starting point

Decode a seven-bit Hamming word under an explicit assumption of at most one flipped bit. Check intact words and every single-bit position, reject malformed or non-binary input and make no claim to detect multiple errors.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Hamming single-bit correction

A concrete starting point
def correct_hamming(word):
    word = list(word)
    if len(word) != 7 or any(type(b) is not int or b not in (0, 1) for b in word):
        raise ValueError("hamming.word")
    syndrome = 0
    for parity in (1, 2, 4):
        value = 0
        for position in range(1, 8):
            if position & parity:
                value ^= word[position-1]
        if value:
            syndrome |= parity
    if syndrome:
        word[syndrome-1] ^= 1
    data = (word[2] << 3) | (word[4] << 2) | (word[5] << 1) | word[6]
    return data, syndrome

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗