Showing posts with label Error Detection and Correction Techniques. Show all posts
Showing posts with label Error Detection and Correction Techniques. Show all posts
Cyclic Redundancy Check - CRC
Sender / CRC Genretor
//CRC-Cyclic Redundancy Check Code
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
void main()
{
int i,j,divisor_len,dividend_len,pid;
char dividend[100],dataword[100], divisor[30],temp[30],quotient[100],remainder[30],divisor1[30];
system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);
printf("Enter dividend: ");
scanf("%s",dataword);
strcpy(dividend,dataword);
printf("Enter divisor : ");
scanf("%s",divisor);
write(pid,&divisor,sizeof(divisor));
//calculate length of data
divisor_len=strlen(divisor);
dividend_len=strlen(dividend);
//create backup of original divisor
strcpy(divisor1,divisor);
//left shift rawbits in dividend with divisor_len-1
for(i=0;i<divisor_len-1;i++)
{
dividend[dividend_len+i]='0';
}
//copy original dividend(without padding bits) into temp
for(i=0;i<divisor_len;i++)
{
temp[i]=dividend[i];
}
for(i=0;i<dividend_len;i++)
{
quotient[i]=temp[0];
//select quitient bit ZERO if first bit of current dividend is ZERO otherwise ONE
if(quotient[i]=='0')
{
//if ZERO selected Divisor became all ZERO bits
for(j=0;j<divisor_len;j++)
{
divisor[j]='0';
}
}
else
{
//if ONE is selected divide with Original divisor
for(j=0;j<divisor_len;j++)
{
divisor[j]=divisor1[j];
}
}
for(j=divisor_len-1;j>0;j--)
{
//do the process of XOR and get Reminder
if(temp[j]==divisor[j])
{
//temp[j]==divisor[j] : Reminder
// 0 == 0 : 0
// 1 == 1 : 1
remainder[j-1]='0';
}
else
{
//temp[j]==divisor[j] : Reminder
// 0 == 1 : 1
// 1 == 0 : 1
remainder[j-1]='1';
}
}
remainder[divisor_len-1]=dividend[i+divisor_len];
strcpy(temp,remainder);
}
for(i=0;i<divisor_len-1;i++)
{
remainder[i]=temp[i];
}
remainder[i]='\0';
system("clear");
printf("\n[%d] - Dataword : %s",strlen(dataword),dataword);
printf("\n[%d] - Divisor : %s",strlen(divisor1),divisor1);
printf("\n[%d] - CRC : %s",strlen(remainder),remainder);
strcat(dataword,remainder);
printf("\n[%d] - Codeword : %s\n",strlen(dataword),dataword);
write(pid,&dataword,sizeof(dataword));
close(pid);
}
Block Parity Check - Error Detection and Correction Techniques
Sender / Block Parity Generator
//block parity sender
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
// one bit for NULL char and
// second for Parity bit
#define Frame_Size 32 // size of frame in bit
#define ROW 4+1 //segments
#define COL 8+2 // m bits in a segment [ +2 for '*' and '\0' ]
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
void blockParity(char myframe[ROW][COL])
{
int i=0,j=0,ROW_count=0,COL_count=0;
//[ Horizontal parity ]
for(i=0;i<ROW;i++)//ROW's Parity Check
{
ROW_count=0;
for(j=0;j<COL-2;j++) //we r using -2 because we want to exclude last two bit that is * and NULL
{
if(myframe[i][j] == '1')//count ROW Parity
{
ROW_count++;
}
}
if((ROW_count % 2) == 0) //set ROW parity bit
myframe[i][j] = '0' ;
else
myframe[i][j] = '1';
}
//[ Virtical parity ]
for(i=0;i<COL-2;i++)//COL's Parity
{
COL_count=0;
for(j=0;j<ROW;j++)
{
if(myframe[j][i] == '1')//count COL Parity
{
COL_count++;
}
}
if((COL_count % 2) == 0) //set COL parity bit
myframe[ROW-1][i] = '0' ;
else
myframe[ROW-1][i] = '1';
}
}
Checksum - Error Detection and Correction Techniques
checksum.h
//checksum header file
#include<stdio.h>
#include<string.h>
# define segment_len 8
# define no_segments 4
# define frameSize 32
int getBit(int frameData,int pos)
{
int code=1; //base
code=code<<(pos-1);
if(frameData & code)
return 1;
else
return 0;
}
void sum(char segment1[],char segment2[])
{
int i,j;
//int segment_len=strlen(segment1);
int ans=0,carry=0;
char ans_segment[9]=" ";
// segment_len--;//because starting from zero
for(i=segment_len-1;i>=0;i--)
{
ans=0;
ans=( (int)segment1[i]-48 ) + ( (int)segment2[i]-48 ) + carry; //sum of bits on each position of two segments
if(ans>=2)//carry genrated
{
carry=1;
if(ans==2)
ans=0; // 1 + 1 = 10 ans
else
ans=1;// 1 + 1 + 1(carry) = 11 ans
}
else
{
carry=0;
}
ans_segment[i]=ans+48;
}
ans_segment[segment_len+1]='\0';
strcpy(segment1,ans_segment);
if(carry==0)
return;
else
sum(segment1,"00000001"); //recursive call of function if carry genrated
}
void complement(char segment[])
{
int i,len=strlen(segment);
for(i=0;i<len;i++)
{
if(segment[i]=='1')
segment[i]='0';
else
segment[i]='1';
}
segment[i]='\0';
}
Subscribe to:
Posts (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.