You are on page 1of 3

Computer Networks (3150710) 200170107039

Practical-4
AIM : To Implement two-dimension parity Check for error Detection
Introduction :

Whenever a message is transmitted, it may get scrambled by noise or data may get corrupted. To avoid this,
we use error-detecting codes which are additional data added to a given digital message to help us detect if
any error has occurred during transmission of the message.

 
Basic approach used for error detection is the use of redundancy bits, where additional bits are added to
facilitate detection of errors.
Some popular techniques for error detection are:
1. Simple Parity check
2. Two-dimensional Parity check
3. Checksum
4. Cyclic redundancy check

Two-dimensional Parity check

Parity check bits are calculated for each row, which is equivalent to a simple parity check bit. Parity
check bits are also calculated for all columns, then both are sent along with the data. At the receiving end these
are compared with the parity bits calculated on the received data.

1
Computer Networks (3150710) 200170107039

Code :

#include <iostream>
using namespace std;

int main()
{

// 1 1 1 1
// 1 1 0 0
// 1 1 0 0
// 1 1 1 1

// 1 0 0 1
// 1 1 1 0
// 1 1 0 0
// 1 0 0 1

int Rmessage[4][4];
bool check = 1;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cin>>Rmessage[i][j];
}
}
for(int j=0;j<3;j++){
int count=0;
for(int i=0;i<3;i++){
if(Rmessage[j][i]==1){
count++;
}
}

if(count%2==Rmessage[j][3]){
//continue
}
else{
check = 0;
}
}
cout<<endl;
for(int j=0;j<3;j++){
int count=0;
for(int i=0;i<3;i++){
if(Rmessage[i][j]==1){
2
Computer Networks (3150710) 200170107039

count++;
}
}
if(count%2==Rmessage[3][j]){
//continue
}
else{
check = 0;
}
}
int Hcount = 0;
int VCount = 0;
if(check == 1){
for(int i=0;i<3;i++){
if(Rmessage[3][i] == 1){
VCount++;
}
if(Rmessage[i][3] == 1){
Hcount++;
}
}
}

if(VCount%2 == Hcount%2 && VCount%2==Rmessage[3][3]){


cout<<"No Error in Message"<<endl;
}
else{
cout<<"Error in Message"<<endl;
}
return 0;
}

Output :

You might also like