0% found this document useful (0 votes)
28 views6 pages

Expt 5b - Implementation of Cyclic Redundance Check Using C-Program

Its a really good pdf

Uploaded by

dishamanjappa
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 (0 votes)
28 views6 pages

Expt 5b - Implementation of Cyclic Redundance Check Using C-Program

Its a really good pdf

Uploaded by

dishamanjappa
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/ 6

Experiment No: 5

Date: 14.06.23

Implementation of CRC (Cyclic Redundancy Check) using C-


Program to perform Error Detection mechanism

Name : Meghavika Baidya


Reg. No : 21BLC1667
Faculty Name : Dr. Jayavignesh T

AIM:

a. To Implement CRC (Cyclic Redundancy check) using C-Program to


perform Error Detection mechanism

SOFTWARE USED:

C Programming Language, Turbo C/C++ compiler, gcc compiler (Linux)

PROCEDURE:

Division in CRC encoder


Division in the CRC decoder for two cases
CODE TEMPLATE
PROGRAM:

#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 crc();

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

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("\nEnter 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("\nData 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("\nFinal data to be sent: %s", data);

printf("\n----------------------------------------\n");
receiver();
return 0;
}
A CRC is constructed to generate a 3 bit FCS for a 4-bit message. The generator pattern is
1011.

a. Show the generation of the codeword at the sender site


b. Show the checking of the codeword at the receiver site (assume no error).
c. Show that the detection algorithm detects error if received codeword is corrupted.

OUTPUT:
RESULT & INFERENCES:

Inference:

1. The given code demonstrates the usage of a cyclic redundancy check


(CRC) program in C to detect errors in transmitted data.

2. The code takes user input for the data to be transmitted and the
generating polynomial (1011) used for CRC calculations.

3. After performing CRC calculations, the code generates a checksum (101)


for the data and appends it to the original data. The final data to be sent is
110110101.

4. The receiver part of the code prompts the user to enter the received data.
It then performs CRC calculations on the received data and compares the
generated checksum (101) with the received checksum. In this case, the
received data matches the generated checksum, indicating that no errors
were detected during transmission.

5. The program concludes by reporting "No error detected," confirming the


successful transmission of the data without any errors. This showcases the
effectiveness of the CRC algorithm in ensuring data integrity.

You might also like