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

CN EXP No 2 CRC

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)
16 views4 pages

CN EXP No 2 CRC

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

2.

Write a program to compute CRC code for the polynomials CRC-


12, CRC-16 and CRC CCIP
Program Code:

A) Generate CRC code for a given data

#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,m,n,cl;
char a[10],b[100],c[100];
printf("\n ENTER POLYNANOMIAL:");
scanf("%s",a);
printf("\n ENTER THE FRAME:");
scanf("%s",b);
m=strlen(a);
n=strlen(b);
for(i=0;i<m;i++) /* To eliminat first zeros in polynomial */
{
if(a[i]=='1')
{
m=m-i;
break;
}
}
for(k=0;k<m;k++) /* To Adjust the polynomial */
a[k]=a[k+i];
cl=m+n-1;
for(i=0;i<n;i++) /* To copy the original frame to c[]*/
c[i]=b[i];
for(i=n;i<cl;i++) /* To add n-1 zeros at the end of frame */
c[i]='0';
c[i]='\0';
/*To make it as a string */
for(i=0;i<n;i++) /* To set polynomial remainder at end of c[]*/
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';
}
for(i=0;i<n;i++) /* To copy original data in c[] */
c[i]=b[i];
printf("\n THE CODEWORD IS: %s",c);
}
INPUT/OUTPUT:
ENTER POLYNANOMIAL: 1011
ENTER THE FRAME: 10011101
THE CODEWORD IS: 10011101011
B) Verify the CRC code

#include<stdio.h>
#include<math.h>
main()
{
int i,j,k,m,n,cl;
char a[10],c[100];
printf("\n ENTER POLYNANOMIAL:");
scanf("%s",a);
printf("\n ENTER THE CRC CODEWORD:");
scanf("%s",c);
m=strlen(a);
cl=strlen(c);
for(i=0;i<m;i++) /* To eliminat first zeros in polynomial */
{
if(a[i]=='1')
{
m=m-i;
break;
}
}
for(k=0;k<m;k++) /* To Adjust the polynomial */
a[k]=a[k+i];
n=cl-m+1;
for(i=0;i<n;i++) /* To check polynomial remainder is zero or not */
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';
}
for(i=0;i<cl;i++) /* To copy original data in c[] */
if(c[i]=='1')
{
printf("\n THERE IS SOME ERROR IN MESSAGE :");
break;
}
if(i==cl)
printf("\n MESSAGE IS CORRECT");
}

INPUT/OUTPUT:
ENTER POLYNANOMIAL: 1011
ENTER THE CRC CODEWORD: 10011101011
MESSAGE IS CORRECT

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