Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

PRACTICAL-6

Aim : Write a program which demonstrates the concept of Error Detection


and correction methods like VRC and LRC .
Hardware Requirement :- Computer or Laptop for run program

Software Requirement:- Turbo c++

Knowledge Requirment :- knowledge require about c programming and how to error


correction and detection method used like VRC and LRC .

 VRC Program :

#include<stdio.h>
#include<conio.h>
int binary(int);
void parity(int[]);

int arr[9],arr1[9];
char chr;
int temp,temp1,i;
void main()
{ char chr1;
clrscr();
printf("Enter Data :");
scanf("%c %c",&chr,&chr1);
temp=chr;
binary(temp);
printf("\nAscii value is : %d\n",temp);
printf("\nBinary Form : ");
for(i=0;i<8;i++)
{
arr1[i]=arr[i];
printf("%d ",arr[i]);
}
printf("\n");
parity(arr);
temp1=chr1;
binary(temp1);
printf("\n\nAscii value is : %d\n",temp1);
printf("\nBinary Form : ");
for(i=0;i<8;i++)
{
printf("%d ",arr[i]);
}
parity(arr);
getch();
}
void parity(int a[])
{
int count;
count=0;
for(i=0;i<8;i++)
{
if(a[i]==1)
count++;
}
if(count%2==0)
a[8]=0;
else
a[8]=1;
count=0;
printf(“Receiver Side :\n”);
printf("\n\nVRC : \n");
for(i=0;i<9;i++)
{
if(i==8)
printf(" | ");
printf("%d ",a[i]);
}
}
int binary(int x)
{
int rem;
int ctr=0,i=1;
do
{
rem=x%2;
arr[i]=rem;
if(rem==1)
{
ctr++;
}
x=x/2;
i++;
}
while(x!=0);
if(ctr%2==0)
{
arr[0]=0;
}
else
{
arr[0]=1;
}
return(0);
}

 LRC Program :

#include<stdio.h>
#include<conio.h>
int binary(int);
void parity(int [],int []);

int arr[8],arr1[8],parityarr[8];
char chr;
int go,temp,temp1,i;
void main()
{ char chr1;
clrscr();
go=0;
Sender:
if(go==0)
printf("Enter Data : \n");
printf("\nEnter a character : ");
scanf("%c %c",&chr,&chr1);
temp=chr;
binary(temp);
printf("\n\nAscii value is : %d\n",temp);
printf("\nBinary Form : ");
for(i=7;i>=0;i--)
{
arr1[i]=arr[i];
printf("%d ",arr[i]);
}
printf("\n");

temp1=chr1;
binary(temp1);
printf("\n\nAscii value is : %d\n",temp1);
printf("\nBinary Form : ");
for(i=7;i>=0;i--)
{
printf("%d ",arr[i]);
}
parity(arr,arr1);
for(i=7;i>=0;i--)
{
arr[i]=0;
arr1[i]=0;
}
getch();
}
void parity(int arr[],int arr1[])
{
printf(“Receiver Side :\n”);
printf("\n\nLRC :\n");
for(i=7;i>=0;i--)
{
printf("%d ",arr[i]);
}
printf("\n");
for(i=7;i>=0;i--)
{
printf("%d ",arr1[i]);
}
printf("\n---------------------\n");
for(i=0;i<8;i++)
{
if(arr[i]==0 && arr1[i]==0 || arr[i]==1 && arr1[i]==1)
{
parityarr[i]=0;
}
else if(arr[i]==1 && arr1[i]==0 || arr[i]==0 && arr1[i]==1)
{
parityarr[i]=1;
}
}
for(i=7;i>=0;i--)
{
printf("%d ",parityarr[i]);
}
}
int binary(int x)
{
int rem;
int ctr=0,i=1;
do
{
rem=x%2;
arr[i]=rem;
if(rem==1)
{
ctr++;
}
x=x/2;
i++;
}
while(x!=0);
if(ctr%2==0)
{
arr[0]=0;
}
else
{
arr[0]=1;
}
return(0);
}
 Questions and Answers
1. Write Full form of LRC and VLC .
 LRC : Longitudinal Redundancy Check
 VRC: Vertical Redundancy Check

 Conclusion
 In this Practical we know about how to detect and correct error throught the
LRC and VRC method.

You might also like