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

A) To Write A Program To Implement CRC Algorithm. Program

The document discusses two programs: 1. A program to implement CRC algorithm that takes in a polynomial and data, applies the CRC algorithm, and outputs the remainder and transmitted data. 2. A program to implement Hamming code that takes in 4 data bits, calculates the parity bits, encodes the data, simulates data transmission with possible errors, detects and corrects errors using the parity bits.

Uploaded by

bhaspv
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)
81 views4 pages

A) To Write A Program To Implement CRC Algorithm. Program

The document discusses two programs: 1. A program to implement CRC algorithm that takes in a polynomial and data, applies the CRC algorithm, and outputs the remainder and transmitted data. 2. A program to implement Hamming code that takes in 4 data bits, calculates the parity bits, encodes the data, simulates data transmission with possible errors, detects and corrects errors using the parity bits.

Uploaded by

bhaspv
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

3. a) To write a program to implement CRC algorithm.

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,lt,lp,lt1,lp1;
char pol[10],temp[20],temp1[20],data[20];
clrscr();
printf("enter polynomial:");
gets(pol);
printf("enter data to send:");
gets(data);
strcpy(temp,data);
for(i=strlen(pol)-1;i>0;i--)
strcat(temp,"0");
printf("\n\t at sender\n");
printf("\nafter adding zero's:%s",temp);
lp=strlen(pol);
lt=strlen(temp);

while(lt>=lp)
{
for(i=0;i<lp;i++)
temp[i]=temp[i]==pol[i]?'0':'1';
while(temp[0]=='0')
{
for(i=0;i<lt;i++)
temp[i]=temp[i+1];
lt=strlen(temp);
}
}
printf("\nremainder:");
for(k=lp-1-lt;k;k--)
{
printf("0");
strcat(data,"0");
}
printf("%s",temp);
strcat(data,temp);
printf("\ntransmitted data:%s\n",data);

printf("\n\t at receiver\n");
strcpy(temp1,data);
lp1=strlen(pol);
lt1=strlen(temp1);
while(lt1>=lp1)
{
for(i=0;i<lp1;i++)
temp1[i]=temp1[i]==pol[i]?'0':'1';
while(temp1[0]=='0')
{
for(i=0;i<lt1;i++)
temp1[i]=temp1[i+1];
lt1=strlen(temp1);
}
}
printf("\nremainder:");
for(k=lp1-1-lt1;k;k--)
{
printf("0");
strcat(data,"0");
}
printf("%s",temp1);
getch();
}

Output:
enter polynomial: 1011
enter data to send: 1101

at sender
after adding zero's: 1101000
remainder: 001
transmitted data: 1101001

at receiver
remainder: 000
3. b) To write a program to implement hamming code.

Program:

#include<stdio.h>
main()
{
int data[10];
int dataatrec[10],c,c1,c2,c3,i;
clrscr();
printf("Enter 4 bits of data one by one\n");
scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);

/*Calculation of even parity*/


data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");


for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;

if(c==0)
{
printf("\nNo error while transmission of data\n");
}
else
{
printf("\nError on position %d",c);

printf("\nData sent : ");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\nData received : ");


for(i=0;i<7;i++)
printf("%d",dataatrec[i]);

printf("\nCorrect message is\n");


/*if errorneous bit is 0 we complement it else vice versa*/
if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;

for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
getch();
}

Output:

Enter 4 bits of data one by one


1
0
1
0

Encoded data is
1010010
Enter received data bits one by one
1
0
1
0
0
1
1

Error on position 1
Data sent : 1010010
Data received : 1010011
Correct message is
1010010

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