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: 3
Aim: Asynchronous Error Detection,Sender’s Part

Code:

//Asynchronous Error Detection


//When data is transmitted , some extra bits are added at the start (header), or end (trailer) to check
//whether the same info has been transmitted or not

//concept of Parity bit

//1 1 1010110 0
//start bit (1) -- parity bit (to make the number of 1s as even) -- 7-bit data word -- end bit (0)

//In this experiment, we append the start bit, end bit, and parity bit

//transmitter end

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

main()
{
int w[8], f[40][10]
,
p = 0;//0 means even
char s[40];
printf("Enter a string:\t"); scanf("%s",
&s);

for(int i = 0; i < strlen(s); i++)


{ for (int j = 0; j < 8; j++)
{
w[j] = (0 != ((s[i+(j/8)]) & (1 << (7-(j
%8))))); if (w[j]) p = !p; //p is the parity bit
//w[i] is the binary word here
}
w[0] = p; p = 0; f[i]
[0] = 1; f[i][9] = 0; for
(int j = 1; j < 9; j++)
f[i][j] = w[j-1]; }
printf("The Transmitted string is:\n"); //f[i][j] is the final string
for (int i = 0; i < strlen(s); i++)
{ printf(" "); for (int j =
0; j < 10; j++)
printf("%d",
f[i][j]);
}
}

Output:

You might also like