0% found this document useful (0 votes)
47 views

Crc16 Error Detecting Code

The document describes a program that implements error detection using CRC-CCITT (16-bit). It takes in a message as binary input, applies the CRC algorithm to generate error checking bits, optionally introduces an error, sends the combined message+check bits, and detects any errors at the receiver using the same CRC algorithm. The program is tested with and without an introduced error.

Uploaded by

Fullmetal
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)
47 views

Crc16 Error Detecting Code

The document describes a program that implements error detection using CRC-CCITT (16-bit). It takes in a message as binary input, applies the CRC algorithm to generate error checking bits, optionally introduces an error, sends the combined message+check bits, and detects any errors at the receiver using the same CRC algorithm. The program is tested with and without an introduced error.

Uploaded by

Fullmetal
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

1.

Write a program for error detecting code using CRC-CCITT (16- bits)
// 11011011 - 8 bit
// 1011 - 4-bit
#include<stdio.h>
#include<stdlib.h>
main()
{
int c[50], b[50], a[17] ={1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
int i, j, m, n=17, q, r, x, y, z, e, pos, fail=1;
printf ("enter no of bits for messages:\n");
scanf ("%d",&m);
printf ("enter the message to be transmitted:\n");
for (i=0; i<m; i++)
{
scanf ("%d", &b[i] );
c[i] = b[i];
}
for (i=m; i<m+n-1; i++)
b[i] = 0;
if ( m<n )
{
printf ("error!!! enter bits again");
exit (0);
}
else
{
y=0;
for (i=0;i<m;i++)
{
if (b[y] = =1)
for (x=y,j=0; x<y+n; x++, j++)
b[x] = b[x] ^ a[j];
else
for (x=y; x<y+n; x++)
b[x] = b[x] ^ 0;
y++;
}
}
for (i=m; i<m+n-1; i++)
c[i] = b[i];
printf ("message to be sent is:\n");
for (i=0; i<m+n-1; i++)
printf ("%d", c[i]);
printf ("\nintroduce error?? yes or no[1 or 0]:\n");
scanf ("%d", &e);
if (e==1)
{
printf("enter the position to be changed:");
scanf("%d",&pos);
if( pos>m)
printf ("\ninvalid position!!");
else
if( c[pos-1]= = 0)
c[pos-1]=1;
else
c[pos-1]=0;
}
printf ("message recieved at reciever site:\n");
for (i=0; i<m+n-1; i++)
printf ("%d", c[i]);
z = 0;
for (i=0; i<m; i++)
{
if (c[z] = = a[0])
{
for (x=z,j=0; x<z+n; x++, j++)
c[x] = c[x] ^ a[j];
}
else
{
for (x=z; x<z+n; x++)
c[x] = c[x] ^ 0;
}
z++;
}
for (i=0; i<m+n-1; i++)
{
if (c[i] = = 1)
{
printf ("\nerror in the message!!!\n");
fail = 0;
break;
}

}
if (fail)
printf ("\nsuccessful transfer of message\n");
}

Case 1: Without error


enter no of bits for messages(>17):

18

enter the message to be transmitted:

1
1

message to be sent is:

1011111111111111110111001101101111

introduce error?? yes or no[1 or 0]:

message received at receiver site:

1011111111111111110111001101101111

successful transfer of message

Process returned 0 (0x0) execution time : 49.103 s

Press any key to continue.

Case 2 : With error


enter no of bits for messages(>17):

18

enter the message to be transmitted:

0
1

message to be sent is:

1010101010101010101000100001110101

introduce error?? yes or no[1 or 0]:

enter the position to be changed:5

message received at receiver site:

1010001010101010101000100001110101

error in the message!!!

Process returned 0 (0x0) execution time: 32.723 s

Press any key to continue.

You might also like