0% found this document useful (1 vote)
36 views4 pages

Lab Report 3

Uploaded by

Hasnat Zamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
36 views4 pages

Lab Report 3

Uploaded by

Hasnat Zamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Green University of Bangladesh

Department of Computer Science and Engineering


(CSE)
Faculty of Sciences and Engineering
Semester: (Spring, Year:2024), B.Sc. in CSE (Day)

Lab Report NO # 03
Course Title: Data Communication Lab
Course Code: CSE 308 Section: 221-D7

Lab Experiment Name: Implementing Cyclic Redundancy Check and


Parity Checker.
Student Details

Name ID

1. Hasnat Zamil 221902001

Lab Date : 01-03-24


Submission Date : 08-03-24
Course Teacher’s Name : Muhaimen Khan
Lab Report Status
Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
LAB REPOPRT NAME

Implementing Cyclic Redundancy Check and Parity Checker.

OBJECTIVES

• Attain knowledge on the cyclic redundancy check (CRC) and how it works.
• Implement CRC is to detect errors that might occur during data
transmission.

PROCEDURE

• Specify the starting CRC value and the CRC polynomial. Initialize CRC to
the initial value.
• Set CRC initial value to 1.
• Repeat for every byte in the stream of data.
• XOR the byte and the CRC for every byte.
• For every bit in the byte 0 If the CRC's least significant bit is 1.
• Use the CRC polynomial and the right shift of one bit to XOR the CRC.
• Alternatively, just move the CRC little to the right.
• The CRC will store the final CRC value once all the bytes have been
processed.

IMPLEMENTATION

#include<stdio.h>
#include<string.h>
#define N strlen(gen_poly)
char data[28];
char check_value[28];
char gen_poly[10];
int data_length,i,j;
void XOR(){
for(j = 1;j < N; j++)
check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');

void receiver(){
printf("Enter the received data: ");
scanf("%s", data);
printf("\n");
printf("Data received: %s", data);
crc();
for(i=0;(i<N-1) && (check_value[i]!='1');i++);
if(i<N-1)
printf("\nError detected");
else
printf("\nNo error detected");
}

void crc(){
for(i=0;i<N;i++)
check_value[i]=data[i];
do{

if(check_value[0]=='1')
XOR();
for(j=0;j<N-1;j++)
check_value[j]=check_value[j+1];
check_value[j]=data[i++];
}while(i<=data_length+N-1);
}

int main()
{
printf("\nEnter data to be transmitted: ");
scanf("%s",data);
printf("\n Enter the Generating polynomial: ");
scanf("%s",gen_poly);
data_length=strlen(data);
for(i=data_length;i<data_length+N-1;i++)
data[i]='0';
printf("\n");
printf("\n Data padded with n-1 zeros : %s",data);
printf("\n");
crc();
printf("\nCRC or Check value is : %s",check_value);
for(i=data_length;i<data_length+N-1;i++)
data[i]=check_value[i-data_length];
printf("\n");
printf("\n Final data to be sent : %s",data);
printf("\n");
receiver();
return 0;
}

OUTPUT

Figure : Output 1 Figure : Output 2

CONCLUSION

Transmission media failures or external interference can result in bit errors (0 changed
to 1 or 1 changed to 0) in data transmission, which can lead to inaccurate data being
received at the receiving end. In order to fix this issue, the data must be checked for
errors at the receiving end before being accepted, and only when the data is accurate.
By employing the Cyclic Redundancy Check method, we can resolve the issue.

You might also like