0% found this document useful (0 votes)
14 views4 pages

Program 8 CRC

Uploaded by

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

Program 8 CRC

Uploaded by

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

Program statement:

a) Generate CRC code for a given data


Program description:
The Cyclic Redundancy Checks (CRC) is the most powerful method for Error-Detection
and Correction. It is given as a kbit message and the transmitter creates an (n – k) bit
sequence called frame check sequence. The out coming frame, including n bits, is precisely
divisible by some fixed number. Modulo 2 Arithmetic is used in this binary addition with no
carries, just like the XOR operation.
Redundancy means duplicacy. The redundancy bits used by CRC are changed by splitting
the data unit by a fixed divisor. The remainder is CRC.

Algorithm
1. A string of n as is appended to the data unit. The length of predetermined divisor is n+ 1.
2. The newly formed data unit 1. A string of n as is appended to the data unit. The length of
predetermined divisor is n+ 1. i.e. original data + string of n as are divided by the divisor
using binary division and remainder is obtained. This remainder is called CRC.
3. Now, string of n O s appended to data unit is replaced by the CRC remainder (which is
also of n bit).
4. The data unit + CRC is then transmitted to receiver.
5. The receiver on receiving it divides data unit + CRC by the same divisor & checks the
remainder.
6. If the remainder of division is zero, receiver assumes that there is no error in data and it
accepts it.
7. If remainder is non-zero then there is an error in data and receiver rejects it.
Program:
#include <stdio.h>
#include <string.h>

int main() {
int i, j, k, m, n, cl;
char a[10], b[100], c[100];

printf("\nENTER POLYNOMIAL: ");


scanf("%s", a);
printf("\nENTER THE FRAME: ");
scanf("%s", b);

m = strlen(a);
n = strlen(b);

// To eliminate first zeros in polynomial


for (i = 0; i < m; i++) {
if (a[i] == '1') {
m = m - i;
break;
}
}

// To adjust the polynomial


for (k = 0; k < m; k++) {
a[k] = a[k + i];
}

cl = m + n - 1;

// To copy the original frame to c[]


for (i = 0; i < n; i++) {
c[i] = b[i];
}

// To add n-1 zeros at the end of frame


for (i = n; i < cl; i++) {
c[i] = '0';
}
c[i] = '\0'; // To make it as a string

// To set polynomial remainder at end of c[]


for (i = 0; i < n; i++) {
if (c[i] == '1') {
for (j = i, k = 0; k < m; k++, j++) {
if (a[k] == c[j]) {
c[j] = '0';
} else {
c[j] = '1';
}
}
}
}

// To copy original data in c[]


for (i = 0; i < n; i++) {
c[i] = b[i];
}

printf("\nTHE MESSAGE IS: %s\n", c);

return 0;
}
OUTPUT:
ENTER POLYNOMIAL: 1011

ENTER THE FRAME: 10011101

THE MESSAGE IS: 10011101011

ENTER POLYNOMIAL: 00101

ENTER THE FRAME: 10101011

THE MESSAGE IS: 1010101101

b) Verify the CRC code


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

int main() {
int i, j, k, m, n, cl;
char a[10], c[100];

printf("\nENTER POLYNOMIAL: ");


scanf("%s", a);
printf("\nENTER THE CRC FRAME: ");
scanf("%s", c);

m = strlen(a);
cl = strlen(c);

// To eliminate first zeros in polynomial


for (i = 0; i < m; i++) {
if (a[i] == '1') {
m = m - i;
break;
}
}

// To adjust the polynomial


for (k = 0; k < m; k++) {
a[k] = a[k + i];
}

n = cl - m + 1;

// To check if polynomial remainder is zero or not


for (i = 0; i < n; i++) {
if (c[i] == '1') {
for (j = i, k = 0; k < m; k++, j++) {
if (a[k] == c[j]) {
c[j] = '0';
} else {
c[j] = '1';
}
}
}
}

// To check for errors in the message


for (i = 0; i < cl; i++) {
if (c[i] == '1') {
printf("\nTHERE IS SOME ERROR IN MESSAGE\n");
break;
}
}
if (i == cl) {
printf("\nMESSAGE IS CORRECT\n");
}

return 0;
}

OUTPUT:
ENTER POLYNOMIAL: 1011

ENTER THE CRC FRAME: 10101011101

THERE IS SOME ERROR IN MESSAGE

ENTER POLYNOMIAL: 01011

ENTER THE CRC FRAME: 10011101011

MESSAGE IS CORRECT

You might also like