Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Name: Kaushik Mazumder

Roll No: ECB19025

Computer Network Lab


Report: 4
Aim: Asynchronous Error Detection, Receiver’s Part

Code:

#include<stdio.h>
#include<string.h>
#include<math.h>

main()
{
char msg[400], op[40];
int rec[40][8], j
= 0, k = 0, p
= 0,
i;
float a = 0;
printf("Enter the received binary string:\n");
scanf("%s", &msg); int len = strlen(msg);

for(i = 0; i < len; i++)


msg[i] -= 48;

i = 1; while(i < len) //even parity


checker
{
if((i%10)>0 && (i%10)<9 && msg[i])
p = !p;
if(!(i%10) && p)
{
printf("The received message is erroneous! Terminating here. .. \
n"); break;
}
i++;
}

printf("The deciphered message is:\n");


for(int i = 1; i < len+1; i++)
{
if((i%10)>1 && (i%10)<9)
a += pow(2,(8-(i%10)))*msg[i]; //convert to char
if(!(i%10)) //for every 10th bit
{
printf("%c", (int)a);
a = 0;
}
}
}
Output:

You might also like