0% found this document useful (0 votes)
17 views7 pages

Wa0006.

The document outlines an experiment to implement Cyclic Redundancy Check (CRC) in C for error detection in data transmission. It explains the differences between error detection and correction, detailing how CRC generates a checksum to identify errors. The experiment includes a code implementation and concludes with a demonstration of CRC's effectiveness in ensuring data integrity.

Uploaded by

traj23it
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)
17 views7 pages

Wa0006.

The document outlines an experiment to implement Cyclic Redundancy Check (CRC) in C for error detection in data transmission. It explains the differences between error detection and correction, detailing how CRC generates a checksum to identify errors. The experiment includes a code implementation and concludes with a demonstration of CRC's effectiveness in ensuring data integrity.

Uploaded by

traj23it
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/ 7

Name: Aniket yadav Div: SE IT B

Roll No.:455 Sign:

DOP: Grade:
DOS:
---------------------------------------------------------------------------------------------------

EXPERIMENT NO. 4

Aim: Write a program in C to implement Cyclic Redundancy Check (CRC).

Theory:

Error Detection and Correction at Data Link Layer:


Error Detection:
Error detection is the process of determining whether any errors have occurred during the
transmission or storage of data. It focuses solely on identifying the presence of an error, without
concern for the number of erroneous bits or the specific type of error. This is typically achieved
through techniques such as parity checks, checksums, and cyclic redundancy checks (CRC), which
generate and verify additional error-detecting codes. However, error detection alone does not
correct errors; it only signals their presence so that appropriate corrective actions, such as
retransmission or error correction mechanisms, can be applied if necessary.

Error Correction:
Error correction is the process of not only detecting the presence of errors in transmitted or stored
data but also determining the exact number of bits that have been corrupted and identifying their
specific locations. Unlike error detection, which only signals the presence of errors, error
correction allows the system to reconstruct the original data without requiring retransmission. This
is achieved using advanced techniques such as Hamming codes, Reed-Solomon codes, and
convolutional codes, which incorporate redundancy into the data to facilitate both error detection
and correction. These methods enable reliable communication and data storage, particularly in
environments where retransmission is costly or impossible, such as deep-space communication,
wireless networks, and memory storage systems.
Difference between Error Detection and Error Correction:

Error detection and error correction are two key processes in ensuring data integrity during
transmission or storage. Error detection focuses solely on identifying whether an error has
occurred, without determining its exact location or the number of corrupted bits. It uses techniques
like parity checks, checksums, and cyclic redundancy checks (CRC) to signal the presence of
errors. In contrast, error correction goes a step further by not only detecting errors but also
determining their exact location and correcting them without requiring retransmission. Techniques
such as Hamming codes, Reed-Solomon codes, and BCH codes enable this process by adding
redundancy to the data. While error detection has lower overhead and is useful when
retransmission is possible, error correction requires more computational resources and is preferred
in scenarios where retransmission is costly or impractical, such as deep-space communication and
memory storage.

Cyclic Redundancy Check(CRC):

Cyclic Redundancy Check (CRC) is an error-detection technique used to identify errors in digital
data during transmission or storage. It works by generating a short, fixed-length checksum (CRC
code) based on the data using polynomial division. The sender appends this CRC code to the data
before transmission. At the receiver’s end, the same polynomial division is performed, and if the
computed CRC does not match the received CRC, it indicates that an error has occurred.

CRC is widely used in network communications, storage devices, and file integrity verification
due to its efficiency in detecting common transmission errors, such as bit flips and burst errors.
However, while CRC can detect errors, it does not correct them; instead, it signals the need for
retransmission if an error is found.

Cyclic Redundancy Check Algorithm:

Choose a Generator Polynomial – A predefined binary divisor (e.g., 1101).

Append Zeros – Add (n-1) zeros to the data, where n is the divisor length.

Binary Division – Divide the modified data by the generator polynomial using XOR.

Get CRC Checksum – The remainder from the division is the CRC code.

Append CRC to Data – Replace the appended zeros with the remainder and transmit.

Receiver Checks for Errors – Divides the received message by the same polynomial.

● If the remainder is zero, the data is error-free.


● If non-zero, an error is detected.
Code:

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

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-----------------------------\n");
printf("Data received: %s", data);

crc();
printf("\nCRC or Check value is : %s", check_value);

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("Sender's Side:\n");
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");

printf("Receiver's Side:\n");
receiver();

return 0;
}

Output:
Without Errors:
With Errors:

Conclusion:
The experiment successfully implemented a Cyclic Redundancy Check (CRC) program in C to
detect errors in data transmission by generating and verifying a CRC checksum using a given
generator polynomial. This demonstrated the effectiveness of CRC in identifying errors, ensuring
data integrity in digital communication and storage systems.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy