0% found this document useful (0 votes)
23 views3 pages

CRC (Dividend, Divisor, Remainder) /: Akshat Agarwal

The program implements error detection using CRC-CCITT (16-bit) cyclic redundancy check. It takes a dataword as input, generates a codeword by appending the remainder from CRC calculation, and checks for errors by recalculating the CRC of the received codeword. The CRC generator polynomial used is x^16 + x^12 + x^5 + 1. It outputs whether the transmission was successful or corrupted based on if the final remainders match.

Uploaded by

champ
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)
23 views3 pages

CRC (Dividend, Divisor, Remainder) /: Akshat Agarwal

The program implements error detection using CRC-CCITT (16-bit) cyclic redundancy check. It takes a dataword as input, generates a codeword by appending the remainder from CRC calculation, and checks for errors by recalculating the CRC of the received codeword. The CRC generator polynomial used is x^16 + x^12 + x^5 + 1. It outputs whether the transmission was successful or corrupted based on if the final remainders match.

Uploaded by

champ
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/ 3

CRC-16

A8. Write a program for Error Detection using CRC-CCITT(16 bits).

Program

# include <stdio.h>
# include <string.h>
# include <stdlib.h>

# define MAX 30

/* crc(dividend , divisor, remainder) */


void crc(char *data, char *gen, char *rem)
{
int i, j, k=0;
char out[MAX]; // xored value of each round

strcpy(out, data);

/* Perform XOR on the msg */


for(i=0; i<strlen(data)-strlen(gen)+1; i++)
{
if(out[i] == '1')
{
for(j=1; j<strlen(gen); j++)
{
out[i+j] = (out[i+j] == gen[j]) ? '0' : '1';
}
}
}

int idx = strlen(out)-strlen(gen)+1;

for(i=0; i<strlen(gen)-1; i++)


{
rem[i] = out[idx+i];
}

int main()
{
int i, j;

char dword[MAX]; // dataword


char augWord[MAX]; // augmented dataword
char cword[MAX]; // codeword
char rem[MAX]; // remainder or syndrome from crc
char gen[] = "10001000000100001";

printf("\nCRC-16 Generator : x^16 + x^12 + x^5 + 1 ");


printf("\nBinary Form : %s", gen);

printf("\n\nEnter Dataword : ");


scanf("%s", dword);

AKSHAT AGARWAL
strcpy(augWord, dword);
for(i=0; i<strlen(gen)-1; i++)
{
strcat(augWord, "0");
}
printf("\nAugmented dataword is : %s",augWord);

crc(augWord, gen, rem);

strcpy(cword, dword);
strcat(cword, rem);
printf("\n\nFinal data transmitted : %s", cword);

char recv[MAX];
printf("\n\nEnter the data received : ");
scanf("%s", recv);

if(strlen(recv) < strlen(cword))


{
printf("\n Invalid input \n");
exit(0);
}

crc(recv, gen, rem);

printf("\nSyndrome = %s ", rem);


for(i=0; i<strlen(rem); i++)
{
if(rem[i] == '1')
{
printf("\nError occured !!! Corrupted data received. \n");
exit(0);
}
}
printf("\nNo Error. Data recieved successfully.\n");
}

AKSHAT AGARWAL
Output

AKSHAT AGARWAL

You might also like