Hamming Code
Hamming Code
• Parity bits: The bit which is appended to the original data of binary
bits so that the total number of 1s is even or odd.
• Even parity: To check for even parity, if the total number of 1s is
even, then the value of the parity bit is 0. If the total number of 1s
occurrences is odd, then the value of the parity bit is 1.
• Odd Parity: To check for odd parity, if the total number of 1s is
even, then the value of parity bit is 1. If the total number of 1s is odd,
then the value of parity bit is 0.
• Hamming Code
~ developed by R.W.Hamming
#include<stdio.h>
void main() {
int data[10];
int dataatrec[10],c,c1,c2,c3,i;
scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
for(i=0;i<7;i++)
printf("%d",data[i]);
for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);
c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
else {
for(i=0;i<7;i++)
printf("%d",data[i]);
for(i=0;i<7;i++)
printf("%d",dataatrec[i]);
if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);