## Hamming Codes and C Implementation Using the Octave GNU Tool

### 7. C Language HammingCode.c/h

##### Supports standard/systematic extended Hamming Codes: (8,4,4) and (16,11,4):

/*
Hamming Distance between code1 and code2
Input
uint16 code1
uint16 code2
Return
uint8 – Hamming Distance
*/
uint8 HammingDistance(uint16 code1, uint16 code2)

/*
Generator of the Extended Hamming Code (8,4,4)
x = [x1,…,x8] = u*G = [u1,u2,u3,u4]*G
Input
uint8 u – input nibble
Return
uint8 x – Hamming output byte
*/
uint8 GeneratorHamming_8_4_4(uint8 u_in)

/*
Syndrome of the Extended Hamming Code (8,4,4)
syndrome = [s1,s2,s3,s4] = x*HT = [x1,x2,…,x8]*HT
Input
uint8 x_in – input Hamming Code
Return
uint8 syndrome – Hamming syndrome [s1,s2,s3,s4]
*/
uint8 SyndromeHamming_8_4_4(uint8 x_in)

/*
Correction of the Extended Hamming Code (8,4,4)
Input
uint8* ptr_x_in – pointer on the input Hamming Code
Return
uint8 flag – TRUE: Hamming code in the pointer is in order (successful correction or it was ok)
FALSE: Hamming code has double error and cannot be corrected
*/
uint8 CorrectionHamming_8_4_4(uint8* ptr_x_in)

/*
Generator of the Extended Hamming Code (16,11,4)
x = [x1,x2,…,x16] = u*G = [u1,u2,…,u11]*G
Input
uint16 u – input nibble
Return
uint16 x – Hamming output byte
*/
uint16 GeneratorHamming_16_11_4(uint16 u_in)

/*
Syndrome of the Extended Hamming Code (16,11,4)
syndrome = [s1,s2,s3,s4,s5] = x*HT = [x1,x2,…,x16]*HT
Input
uint16 x_in – input Hamming Code
Return
uint8 syndrome – Hamming syndrome [s1,s2,s3,s4,s5]
*/
uint8 SyndromeHamming_16_11_4(uint16 x_in)

/*
Correction of the Extended Hamming Code (16,11,4)
Input
uint16* ptr_x_in – pointer on the input Hamming Code
Return
uint8 flag – TRUE: Hamming code in the pointer is in order (successful correction or it was ok)
FALSE: Hamming code has double error and cannot be corrected
*/
uint8 CorrectionHamming_16_11_4(uint16* ptr_x_in)