Single Bit Parity Check
Sender
/*Single bit Parity check*/
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
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;
}
int getParity(char targeted_frameData[])
{
//find the even parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(targeted_frameData[i]=='1') //count total no. of 1
counter++;
}
if(counter % 2 == 0 )//Even parity
return 0;
else
return 1;
}
void main()
{
int frameData,i,k=0,flag,pid,frame_size=32;;
char targeted_frameData[34];
pid=open("pipe",O_WRONLY);
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
targeted_frameData[k++]=getBit(frameData,i) + 48;
}
//Set Parity bit
targeted_frameData[k++]=getParity(targeted_frameData) + 48;
targeted_frameData[k++]='\0';
printf("\n\nTageted Frame : %s\n",targeted_frameData);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
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;
}
int getParity(char targeted_frameData[])
{
//find the even parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(targeted_frameData[i]=='1') //count total no. of 1
counter++;
}
if(counter % 2 == 0 )//Even parity
return 0;
else
return 1;
}
void main()
{
int frameData,i,k=0,flag,pid,frame_size=32;;
char targeted_frameData[34];
pid=open("pipe",O_WRONLY);
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
targeted_frameData[k++]=getBit(frameData,i) + 48;
}
//Set Parity bit
targeted_frameData[k++]=getParity(targeted_frameData) + 48;
targeted_frameData[k++]='\0';
printf("\n\nTageted Frame : %s\n",targeted_frameData);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
Receiver
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getParity(char frameData[])
{
//recount parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(frameData[i]=='1')
counter++;
}
if(counter % 2 == 0 ) //Even parity
return 0;
else
return 1;
}
void main()
{
int pid,i=0,parity;
char frameData[34];
pid=open("pipe",O_RDONLY);
read(pid,&frameData,sizeof(frameData));
parity=getParity(frameData);
if(frameData[32]==(parity+48) )
{
printf("\n\nNo ERROR Found...!\n\n");
//print data from named pipe if no error is there
while(frameData[i]!='\0')
{
printf("%c",frameData[i++]);
}
}
else
{
printf("\n\nERROR DETECTED...!\n\n");
}
}
#include<fcntl.h>
#include<string.h>
int getParity(char frameData[])
{
//recount parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(frameData[i]=='1')
counter++;
}
if(counter % 2 == 0 ) //Even parity
return 0;
else
return 1;
}
void main()
{
int pid,i=0,parity;
char frameData[34];
pid=open("pipe",O_RDONLY);
read(pid,&frameData,sizeof(frameData));
parity=getParity(frameData);
if(frameData[32]==(parity+48) )
{
printf("\n\nNo ERROR Found...!\n\n");
//print data from named pipe if no error is there
while(frameData[i]!='\0')
{
printf("%c",frameData[i++]);
}
}
else
{
printf("\n\nERROR DETECTED...!\n\n");
}
}
Generate Error
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void dispFrameData(char targeted_frameData[])
{
int i=0;
//print data from named pipe
while(targeted_frameData[i]!='\0')
{
printf("%c",targeted_frameData[i++]);
}
}
void generateError(char targeted_frameData[])
{
int f=1,pos;
do
{
printf("Enter bit Position : ");
scanf("%d",&pos);
if(pos>=0 && pos<32)
{
if(targeted_frameData[pos]=='1')
targeted_frameData[pos]='0';
else
targeted_frameData[pos]='1';
}
else
{
printf("\n\t Invalid Position...!\n");
}
dispFrameData(targeted_frameData);
printf("\nDo u want to generate more ERROR ? [1 / 0] : ");
scanf("%d",&f);
}while(f==1);
}
void main()
{
int pid,i=0,parrity;
char targeted_frameData[34];
pid=open("pipe",O_RDONLY);
read(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
printf("\n\nFrame Data\n\n");
dispFrameData(targeted_frameData);
generateError(targeted_frameData);
pid=open("pipe",O_WRONLY);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
#include<fcntl.h>
#include<string.h>
void dispFrameData(char targeted_frameData[])
{
int i=0;
//print data from named pipe
while(targeted_frameData[i]!='\0')
{
printf("%c",targeted_frameData[i++]);
}
}
void generateError(char targeted_frameData[])
{
int f=1,pos;
do
{
printf("Enter bit Position : ");
scanf("%d",&pos);
if(pos>=0 && pos<32)
{
if(targeted_frameData[pos]=='1')
targeted_frameData[pos]='0';
else
targeted_frameData[pos]='1';
}
else
{
printf("\n\t Invalid Position...!\n");
}
dispFrameData(targeted_frameData);
printf("\nDo u want to generate more ERROR ? [1 / 0] : ");
scanf("%d",&f);
}while(f==1);
}
void main()
{
int pid,i=0,parrity;
char targeted_frameData[34];
pid=open("pipe",O_RDONLY);
read(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
printf("\n\nFrame Data\n\n");
dispFrameData(targeted_frameData);
generateError(targeted_frameData);
pid=open("pipe",O_WRONLY);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
Subscribe to:
Post Comments (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)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment