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

LRC Code

This code implements a basic line coding scheme with parity bits for error detection. It includes functions for the sender to encode the data into frames with parity bits, and for the receiver to decode the frames and check the parity bits to detect errors. The sender first divides the data into frames of 7 bits each and adds an 8th parity bit. It then displays the encoded frames. The receiver decodes the received frames, checks the parity bits, and either accepts the data without errors or rejects it if an error is detected.

Uploaded by

s81924465
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

LRC Code

This code implements a basic line coding scheme with parity bits for error detection. It includes functions for the sender to encode the data into frames with parity bits, and for the receiver to decode the frames and check the parity bits to detect errors. The sender first divides the data into frames of 7 bits each and adds an 8th parity bit. It then displays the encoded frames. The receiver decodes the received frames, checks the parity bits, and either accepts the data without errors or rejects it if an error is detected.

Uploaded by

s81924465
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Code (LRC Program):

#include<conio.h>
#include<stdio.h>

char data[64];
int fram[64],frames;
int msg[8][8],m[8][8]; //maximum 7 frames
int len;

void sender()
{
int length,i,j,k,count,bit,s,p;
clrscr();
frames=0;
printf("\n\n\t\t---------------Sender Side---------------\n\n");

printf("\nEnter the data: ");


scanf("%s",data); //accept data in character format
len=strlen(data); //length of character data

for(i=0; i<len; i++)


{
fram[i]=(int)data[i]; //typecasting to ascii value 48 for 0 & 49 for 1
fram[i]=fram[i]%48; //to get 0 & 1
}

frames=len/7; //calculation of frames

for(i=0, k=0; i<frames; i++) //converting 1-dimensional to 2-dimensional


{
if(k<len)
{
for(j=0; j<7; j++)
{
msg[i][j]=fram[k];
k++;
}
}
}

for(i=0;i<frames;i++) // adding parity bit


{
count=0;
for(j=0;j<7;j++)
{
if(msg[i][j]==1)
{
count++;
}
}

if(count%2==0)
msg[i][j]=0;
else
msg[i][j]=1;
}

printf("\n\nCalculation of LRC:\n\n");
for(i=0;i<frames;i++)
{
for(j=0;j<=7;j++)
{
printf("%d ",msg[i][j]);
}
printf("\n\n");
}

printf("\n\n\n Data sent:\t");


for(i=0;i<frames;i++)
{
for(j=0;j<=7;j++)
{
printf("%d",msg[i][j]);
}
printf(" ");
}

int receiver()
{
int i,j,k,cnt,f1=0;

printf("\n\n\t\t---------------Receiver Side---------------\n\n");

printf("\n\nEnter Data received : ");


scanf("%s",data); //accept data in character format
len=strlen(data); //length of character data

for(i=0; i<len; i++)


{
fram[i]=(int)data[i]; //typecasting to ascii value 48 for 0 & 49 for 1
fram[i]=fram[i]%48; //to get 0 & 1
}

frames=len/8; //frames=len/7; in sender

for(i=0, k=0; i<frames; i++) //converting 1-dimensional to 2-dimensional


{
if(k<len)
{
for(j=0; j<8; j++)
{
m[i][j]=fram[k];
k++;
}
}
}

for(i=0;i<frames;i++) // checking parity bit


{
cnt=0;
for(j=0;j<8;j++)
{
if(m[i][j]==1)
{
cnt++;
}
}

if(cnt%2==0)
{
if(m[i][j]==0)
f1=1;
else
{
f1=0;
printf("\n\nData rejected...(1)!!!");
return(0);
}

}
else
{
if(m[i][j]==1)
f1=1;
else
{
f1=0;
printf("\n\nData rejected...!!!");
return(0);
}
}
}

if(f1==1)
{
printf("\n\nOriginal data : ");
for(i=0;i<frames;i++)
{
for(j=0;j<=6;j++)
{
printf("%d",m[i][j]);
}
printf(" ");
}
}
printf("\n\nData accepted...");
return 0;
}

void main()
{
clrscr();
sender();
receiver();
getch();
}

Output:

You might also like