Data Communication Lab 4
Data Communication Lab 4
Lab Report NO # 03
Course Title: Data Communication Lab
Course Code: CSE 308 Section: 223 D3
Lab Experiment Name: Implementation of Hamming Code for Even Parity Checking
Student Details
Name ID
Alik Ahmed Tamim 223002082
Lab Date :
Submission Date : 27-04-2025
Course Teacher’s Name : Rusmita Halim Chaity.
OBJECTIVES
PROCEDURE
The Hamming Code is simply the use of extra parity bits to allow the identification of an
error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in binary
form.
(a) Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the
least significant
position (1, 3, 5, 7, 9, 11, etc ).
(b) Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the
second
position from the least significant bit (2, 3, 6, 7, 10, 11, etc).
(c) Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the
third position
from the least significant bit (4–7, 12–15, 20–23, etc).
(d) Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the
fourth position
from the least significant bit bits (8–15, 24–31, 40–47, etc).
(e) In general, each parity bit covers all bits where the bit-wise AND of the parity position and
the bit
position is non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the positions
it checks
is odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
IMPLEMENTATION
lOMoARcPSD|25028670
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class hamming{
public:
string data;
int m , r = 0;
char * msg;
hamming(string data){
this->data = data;
reverse(data.begin(),data.end());
m = data.size();
int power = 1;
setRedundantBits();
}
void showmsg(){
cout << "the data packet to be sent is : ";
for(int i = m+r ; i >= 1 ; i--){
cout << msg[i] << " ";
}
cout << endl;
}
void setRedundantBits(){
int bit = 0;
bit++;
}
showmsg();
}
void receiver(){
if(ans.find('1') != string::npos){
int power = 1;
int wrongbit = 0;
}
cout << "bit number " << wrongbit << " is wrong and having error " << endl;
}
else{
cout << "correct data packet received " << endl;
}
}
};
int main(){
string data = "1010110";
hamming h(data);
h.receiver();
return 0;
}
OUTPUT
Data-1010110
M (Data Size) : 7
r=4
p1 -1, 3, 5, 7, 9, 11
p2 -2, 3, 6, 7, 10, 11
p3 -4, 5, 6, 7
p4 -8, 9, 10, 11
11 10 9 8 7 6 5 4 3 2 1
1 0 1 0 1 1 0
p1 11 10 9 8 7 6 5 4 3 2 1
1 0 1 0 1 1 0 1
lOMoARcPSD|25028670
P2 11 10 9 8 7 6 5 4 3 2 1
1 0 1 0 1 1 0 0 1
p3 11 10 9 8 7 6 5 4 3 2 1
1 0 1 0 1 1 0 0 0 1
p4 11 10 9 8 7 6 5 4 3 2 1
1 0 1 0 0 1 1 0 0 0 1
DISCUSSION
Hamming codes are a class of error-correcting codes used in digital communication and data
storage to detect and correct errors. Developed by Richard Hamming in the 1950s, they add
extra parity bits to data to ensure accurate transmission. Hamming codes work by inserting
redundant bits at specific positions within a data word. These bits are calculated to check and
correct errors. The receiver can use the parity bits to detect errors, and in some cases, correct
single-bit errors, improving data reliability. Hamming codes are efficient for single-bit error
correction, but they have limitations. They can't correct multiple errors within the same data
word. Despite this, Hamming codes remain a fundamental concept in information theory,
forming the basis for more advanced error-correction codes like Reed-Solomon codes and Turbo
codes, which are used in modern communication systems to ensure robust data transmission.