Posts

Bit stuffing sender

 #include <stdio.h> void main() { char str[100],ptrn[7]="011111",dest[100]; int i,j=0,k=0,c=0; printf ("Flag is 0111110."); printf ("\nEnter The Data : \t"); scanf ("%s",str); while (ptrn[j]!='\0') { dest[k]=ptrn[j]; j++; k++; } dest[k]='1'; k++; dest[k]='0'; k++; j=0; for (i=0;str[i]!='\0';i++) { if (str[i]==ptrn[j]) { dest[k]=str[i]; k++; c++; j++; if (c==6) { dest[k]='0'; c=0; j=0; k++; } } else { dest[k]=str[i]; j=0;c=0; k++; if (str[i]==ptrn[j]) { j++;c++;  } } } j=0; while (j<=5) { dest[k]=ptrn[j]; j++; k++; } dest[k]='1'; k++; dest[k]='0'; dest[k+1]='\0'; printf ("sending Data .... %s",dest); } 

Parity bit sending receiving side

 #include <stdio.h> #include <stdlib.h> int checking(char *data) {  int i=0,num;  while (data[i]!='\0')  {  num=data[i]-48;  if (num=='0'||num=='1')  {  i++;  }  else  {  return 0;  }  }  return 1; } int main() {  char data[40],rdata[40];  int i=0,count=0,check;  printf("Enter the data : \t");  scanf ("%s",data);  check=checking(&data[0]);  printf ("%d is num",check);  if (check==0)  {  printf ("Error.....\nEntered Data is Wrong");  return 0;  }  else if (check==1)  {  printf ("Entered Data is Correct.");  }  while (data[i]!='\0') {   if (data[i]=='1')  {  count++;  i++;  }  else  {  i++;  } }  if (count%2==1)  {  data[i]='1';  data[i+1]='\0';  printf ("\nData to be sent : %s",data);  } ...

Bit stuffing recever

 #include <stdio.h> #include <string.h> void main() {  char str[100],data[100],ptrn[7]="011111";  printf ("Enter the data : \t");  scanf("%s",&str);  int i,j=0,k=0,c=0;  printf ("%d",strlen(str));  for (i=8;i<strlen(str)-8;i++)  {  if (str[i]==ptrn[j])  {  data[k]=str[i];  k++;  j++;  c++;  if (c==6)  {  i++;  j=0;  c=0;  }  }  else  {  data[k]=str[i];  k++;  j=0;  c=0;  if (str[i]==ptrn[j])  {  j++;  c++;  }  }  }  data[k]='\0';  printf ("Received Data.... %s",data); } 

Parity

 bool getParity(unsigned int n) {  bool parity = 0;  while (n)  {  parity = !parity;  n = n & (n - 1);  }  return parity; } int main() {  unsigned int n = 7;  printf("Parity of no %d = %s", n,  (getParity(n)? "odd": "even"));  getchar();  return 0; } 

Crc

 #include<stdio.h> #include<conio.h> void main() { int i,f[20],n[50],div[50],j,temp,quotient[20],z[10]; printf("enter the number\n"); for(i=0;i<8;i++) { scanf("%d",&n[i]); } printf("enter the divisor\n"); for(i=0;i<4;i++) { scanf("%d",&div[i]); } for(i=8;i<12;i++) { n[i]=0; } for(i=0;i<8;i++) { temp=i; if(n[i]==1) { for (j=0;j<4;j++) { if (n[temp]==div[j]) {n[temp]=0; f[j]=0;} else {n[temp]=1; f[j]=1;} temp=temp+1; } quotient[i]=1; } else quotient[i]=0; } printf("\nthe quotient is \n"); for(i=0;i<8;i++) printf("%d",quotient[i]);  printf("\n and the remainder is \n "); for(j=0;j<4;j++) printf("%d",f[j]); getch(); } 

Ham

#include <math.h> #include <stdio.h> int input[32]; int code[32]; int ham_calc(int, int); void solve(int input[], int); int ham_calc(int position, int c_l) {  int count = 0, i, j;  i = position - 1;    while (i < c_l) {  for (j = i; j < i + position; j++) {  if (code[j] == 1)  count++;  }  i = i + 2 * position;  }  if (count % 2 == 0)  return 0;  else  return 1; } void solve(int input[], int n) {  int i, p_n = 0, c_l, j, k;   i = 0;    while (n > (int)pow(2, i) - (i + 1)) {  p_n++;  i++;  }  c_l = p_n + n;  j = k = 0;    for (i = 0; i < c_l; i++) {    if (i == ((int)pow(2, k) - 1)) {  code[i] = 0;  k++;  }  else {  code[i] = input[j];  j++;  }  }  for (i = 0; i < p_n; i++) {  int position = (int)pow(2, i);  int value = ham_calc(position...

Byte stuffing sending receiving

 #include <stdio.h> int main() {  char data[100],sdata[100],rdata[100],rrdata[100];  int i=0,j=1;  printf ("$ is Flag and @ is Escape Character.\n");  printf ("Enter the Message : ");  scanf ("%s",&data);  sdata[0]='$';  while (data[i]!='\0')  {  if (data[i]=='$'||data[i]=='@')  {  sdata[j]='@';  j++;  sdata[j]=data[i];  }  else  {  sdata[j]=data[i];  }  i++;  j++;  }  sdata[j]='$';  sdata[j+1]='\0';  printf ("Sending data .... %s",sdata);  i=0;  printf ("\n\n");  while (sdata[i]!='\0')  {  rdata[i]=sdata[i];  i++;  }  rdata[i]='\0';  i=0;  for(j=1;rdata[j]!='\0';j++)  {  if (rdata[j]=='@')  {  j++;  rrdata[i]=rdata[j];  }   else if (rdata[j]=='$')  {  rrdata[i]=rdata[j+1];  }  else  {  rrdat...