Hamming Code Algorithm
In telecommunication, a Hamming code is a linearerror-correcting code named after its inventor, Richard Hamming. Hamming codes can detect up to two simultaneous bit errors, and correct single-bit errors; thus, reliable communication is possible when the Hamming distance between the transmitted and received bit patterns is less than or equal to one. By contrast, the simple parity code cannot correct errors, and can only detect an odd number of errors.
In mathematical terms, Hamming codes are a class of binary linear codes. For each integer there is a code with m parity bits and 2m − m − 1 data bits. The parity-check matrix of a Hamming code is constructed by listing all columns of length m that are pairwise independent. Hamming codes are an example of perfect codes, codes that exactly match the theoretical upper bound on the number of distinct code words for a given number of bits and ability to correct errors.
Because of the simplicity of Hamming codes, they are widely used in computer memory (RAM). In particular, a single-error-correcting and double-error-detecting variant commonly referred to as SECDED.
Hamming code in C
Hamming code----- Encoding
Enter 4 bit data : 1011
Encoded data 0 1 0 1 0 1 1
Hamming code----- Decoding
Enter encoded bits as received : 0 1 0 1 1 1 1
Error received at bit number 5 of data
Correct data should be : 0101011
Arsalan Khan on February 07, 2017:
This Program is not working in Borland C++....Can you please post the same code for borland c++....it will be my pleasure...
kgiyu on September 03, 2013:
jack on September 08, 2011:
nice please display hamming code program for 7 bit
jim on September 08, 2011: