Error Correcting Encoder-Decoder. Stage 4/5

Bit-level correction code

Report a typo

Description

For errors like on the previous stage, simple code from stage 2 doesn't work, because all of 3 symbols will be with errors. Also, we can't write triples of bits like symbols in stage 2, because some triples will be in different bytes. Because of this, 1 triple of bits can contain 2 errors and this triple can't be corrected.

For this reason, we need another correcting code. We will write every bit twice, in every byte 2 last bits will be bits of parity. The parity bit is the sum of the data bits modulo 2. In that way, we write 3 input data bits in one byte.

hamming encoding

For decoding, we find a pair with error (where the two bits that are supposed to be similar are, in fact, different after receiving the byte). If the error inside data pairs (first 3 pairs) then you can calculate the real bit which was there before sending using the scheme below. If an error inside a parity bits you should do nothing since data bits are correct.

hamming decoding

The program in this stage should work in 3 modes: encode, send and decode.

If the mode is encode then you need to take the text from send.txt, convert it to ready-to-send form (where you have three significant bits per byte) and save the resulted bytes into the file named encoded.txt.

If the mode is send, you should take the file from encoded.txt and simulate the errors in its bytes (1 bit per byte) and save the resulted bytes into the file named received.txt.

If the mode is decode, you should take the file from received.txt and decode it to the normal text. Save the text into the file named decoded.txt.

Examples

The greater-than symbol followed by a space (> ) represents the user input. Notice that it's not part of the input.

Example 1:

Write a mode: > encode

send.txt:
text view: Test
hex view: 54 65 73 74
bin view: 01010100 01100101 01110011 01110100

encoded.txt:
expand: 001100.. 110011.. 000000.. 111100.. 001100.. 110011.. 111100.. 001111.. 001111.. 110011.. 0000....
parity: 00110011 11001100 00000000 11110000 00110011 11001100 11110000 00111100 00111100 11001100 00000000
hex view: 33 CC 00 F0 33 CC F0 3C 3C CC 00

Example 2:

Write a mode: > send

encoded.txt:
hex view: 33 CC 00 F0 33 CC F0 3C 3C CC 00
bin view: 00110011 11001100 00000000 11110000 00110011 11001100 11110000 00111100 00111100 11001100 00000000

received.txt:
bin view: 10110011 11011100 00100000 11010000 00110010 11011100 10110000 01111100 00110100 10001100 00010000
hex view: B3 DC 20 D0 32 DC B0 7C 34 8C 10

Example 3:

Write a mode: > decode

received.txt:
hex view: B3 DC 20 D0 32 DC B0 7C 34 8C 10
bin view: 10110011 11011100 00100000 11010000 00110010 11011100 10110000 01111100 00110100 10001100 00010000

decoded.txt:
correct: 00110011 11001100 00000000 11110000 00110011 11001100 11110000 00111100 00111100 11001100 00000000
decode: 01010100 01100101 01110011 01110100 0
remove: 01010100 01100101 01110011 01110100
hex view: 54 65 73 74
text view: Test
Write a program
IDE integration
Checking the IDE status
___

Create a free account to access the full topic