Hey guys i am uploading this program i made in my college today ,its simple hamming code word generation program for N bits data you enter and it will show you the code word
Hamming code is a popular error detection and error correction method in data communication. Hamming code can only detect 2 bit error and correct a single bit error which means it is unable to correct burst errors if may occur while transmission of data.
Please Like and share if helped for you , thanks
Enter any no of bits and get its hamming code !
This code is for even Piraty ,you may edit it and convert it to generate odd piraty .
C++ Implementation :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
int a,b,c[30],d,r=0,d1;
cout<< " Enter the No of Data Bits you want to Enter : " ; cin>>a;
while (a+r+1>pow(2,r))
{ r++; }
cout<< "No of data bits to be added " <<r<< " : Total Bits :" <<a+r<<endl;
cout<< " Enter the Data Bits One by One :" <<endl;
for ( int i=1;i<=a;++i) cin>>c[i];
cout<<endl<< " Data bits entered : " ;
for ( int i=1;i<=a;++i)
cout<<c[i]<< " " ;
cout<<endl;
int data[a+r];
d=0;
d1=1;
for ( int i=1;i<=a+r;++i)
{ if ((i)==pow(2,d))
{data[i]=0;
++d;
}
else
{ data[i]=c[d1];
++d1;
}
}
cout<< " Data Bits are Encoded with Piraty bits(0): " ;
for ( int i=1;i<=a+r;++i)
cout<<data[i]<< " " ;
d1=0; int min,max=0,piraty,s,j;
for ( int i=1;i<=a+r;i=pow(2,d1))
{ ++d1; piraty=0; j=i;
s=i;
min=1;
max=i;
for ( j;j<=a+r;) { for ( s=j;max>=min && s<=a+r;++min,++s)
{ if (data[s]==1) piraty++;}
j=s+i;
min=1;
}
if (piraty%2==0)
{ data[i]=0; }
else { data[i]=1; }
}
cout<<endl<< " Hamming codeword bits for even piraty are : " ;
for ( int i=1;i<=a+r;++i)
cout<<data[i]<< " " ;
cout<<endl<<endl;
}

Comment below if you have any queries related to above hamming code program in C++.
OutPut :