Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Saturday 12 November 2016

LRC (longitudinal redundancy check)

LRC stands for longitudinal redundancy check In telecommunication, a longitudinal redundancy check (LRC) or horizontal redundancy check is a form of redundancy check that is applied independently to each of a parallel group of bit streams. The data must be divided into transmission blocks, to which the additional check data is added.



[ SENDER SIDE ]

#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBinary(int num,int pos)
{
 int code=1;
 code=code<<(pos-1);
 if(num & code)
  return 1;
 else
  return 0;
}
findLRC(char str[][50],int no_of_str,char parity[50])
{
int count = 0 , j = 0 , i = 0 ;
int k = 0 ;
printf("\n\n");
for(i = 0 ; i < 8 ; i++)
{
for(j = 0 ; j < no_of_str ; j++)
{
//printf("%c",str[j][i]);
if(str[j][i]=='1')
{
count++ ;
}
}
if(count % 2 == 0)
{
parity[k] = '0' ;
}
else
{
parity[k] = '1' ;
}
k++ ;
count = 0 ;
}
parity[k] = '\0';
}
void generateError(char ans[])
{
 int exitflag=1,pos;
 do
 {
  printf("Enter Position : ");
  scanf("%d",&pos);
  if(pos>=0 && pos<strlen(ans))
  {
   if(ans[pos]=='1')
    ans[pos]='0';
   else
    ans[pos]='1';
  }
  else
  {
   printf(" \t>>>Position is out of range<<<\n");
  }
  printf("Want to Generate More Error (1 / 0) : ");
  scanf("%d",&exitflag);
 }while(exitflag==1);
}

int main()
{
int no_of_data ;
int i = 0 ;
int arr[10];

char str[10][50];
char parity[50];
char data[80];

printf("\n How many data : ");
scanf("%d",&no_of_data);
for(i=0;i<no_of_data;i++)
{
printf("\n Enter number : ");
scanf("%d",&arr[i]);
printf("\n No is %d " , arr[i]);
}
int j ;int k = 0 ;
for(i=0;i<no_of_data;i++)
{
for(j=8;j>0;j--)
{
  str[i][k++]=getBinary(arr[i],j)+48;
}
str[i][k]='\0';
k = 0 ;
}
for(i=0;i<no_of_data;i++)
{
printf("\n Binary is %s",str[i]);
}
findLRC(str,no_of_data,parity);
printf("\n Parity is %s ", parity);
for(i=0;i<no_of_data;i++)
{
strcat(data,str[i]);
}
int flag = 0 ;
printf("\n Want to Generate Error (1 / 0) : ");
  scanf("%d",&flag);
  if(flag==1)
  {
  generateError(data);
  printf("\n======================================================");
  printf("\nData to Be Send With Parity and with Error : %s",data);
  printf("\n======================================================\n");
  }

strcat(data,parity);

int pid ;
system(">pipe");
pid = open("pipe",O_WRONLY);
printf("\n Final data is %s " , data);
write(pid,&no_of_data,sizeof(no_of_data));
write(pid,&data,sizeof(data));
return 0 ;
}



[ RECEIVER SIDE ]


#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBinary(int num,int pos)
{
 int code=1;
 code=code<<(pos-1);
 if(num & code)
  return 1;
 else
  return 0;
}
findLRC(char str[][50],int no_of_str,char parity[50])
{
int count = 0 , j = 0 , i = 0 ;
int k = 0 ;
printf("\n\n");
for(i = 0 ; i < 8 ; i++)
{
for(j = 0 ; j < no_of_str ; j++)
{
//printf("%c",str[j][i]);
if(str[j][i]=='1')
{
count++ ;
}
}
if(count % 2 == 0)
{
parity[k] = '0' ;
}
else
{
parity[k] = '1' ;
}
k++ ;
count = 0 ;
}
parity[k] = '\0';
}
void main()
{
int no,j=0,len,i=0,k,pid;
char data[80];//={"000000010000001011"}//1 = 00000001, 2 = 00000010, parity = 11
int no_of_data=2;
char totalData;
char parity[50];
pid=open("pipe",O_RDONLY);

//Commenting this as it is not working in windows
read(pid,&no_of_data,sizeof(no_of_data));
read(pid,&data,sizeof(data));


printf("\nno of data : %d",no_of_data);
printf("\ndata : %s",data);
k = 0 ;
char str[15][50];
k=0;
for(i=0;i<no_of_data;i++)
{
for(j=0;j<8;j++)
{
str[i][j] = data[k++];
str[i][j+1] = '\0';
}
}
for(i=0;i<no_of_data;i++)
{
printf("\n Str is %s",str[i]);
}

findLRC(str,no_of_data,parity);
char redaparity[50];
j=0;
for(i=no_of_data*8;i<strlen(data);i++){
redaparity[j++]=data[i];
}
redaparity[j]='\0';

printf("\nReceived parity %s", redaparity);
printf("\nCalculated parity %s", parity);
int isSame=strcmp(redaparity, parity);
if(isSame==0){
printf("\nDATA IS CORRECT");
}
else{
printf("\nDATA IS INCORRECT");
}

}



Monday 31 October 2016

Now Great News For Students / Job Seekers !!!


We are providing Software Training in following Subjects



Basic Level:
1. C
2. C++

Programming Level
1. JAVA
2. PHP

Database:

1. SQL, MYSQL, PLSQL
2. ORACLE

Web:

1. CSS, CSS-3,
2. Bootstrap, 

3. HTML, HTML-5

Mobile Computing:

1. Android

Extras:
1. FON (Fundamental Of Networking) Practicals for MCA Students

For more detail please Contact Us on below numbers


Ahmedabad-Gujarat Region

Ami Sharma (M-9712630253, 7990318870)
Pankaj Sharma(M-8460479175)