Type Here to Get Search Results !

Bit stuffing on given binary data

 Bit stuffing on given binary data


Algorithm for Bit−Stuffing

1. Start

2. Initialize the array for transmitted stream with the special bit pattern 0111 1110 which indicates the beginning of the frame.

3. Get the bit stream to be transmitted in to the array.

4. Check for five consecutive ones and if they occur, stuff a bit 0

5. Display the data transmitted as it appears on the data line after appending 0111 1110 at the end

6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed bits

7. Display the received bit stream

8. Stop

program: 

#include<stdio.h> 

#include<conio.h>

 #include<math.h> 

main()

{

int   b[100],b1[100],l,k,n=0,i,j,z,i1,s[20],f[8]={0,1,1,1,1,1,1,0},j1;

static int a[100]; char ch='y',bs[50]; 

clrscr(); 

do

{

i1=z=n=0; 

clrscr();

printf("\n Enter the bit string(space for each byte)"); 

gets(bs);

for(i=0;bs[i]!='\0';i++)

if(bs[i]!=' ')

b[n++]=bs[i]-'0';

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

{

if(b[i]==1)

{

i1++; 

if(i1==5){s[z++]=i+1;i1=0;

}

}

else 

i1=0;

} j1=j=0;

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

{

while(j<s[i]) 

b1[j1++]=b[j++]; 

b1[j1++]=0;

}

while(j1<n+z) 

b1[j1++]=b[j++];

l=n/8; 

for(i=0;l>0;i++)

{

a[i]=l%2; l=l/2;

}

printf("\nAfter stuffing :"); 

for(j=7;j>=0;j--)

printf("%d",a[j]); 

printf(" "); 

for(k=0;k<8;k++) 

printf("%d",f[k]);

 printf(" "); 

for(k=0;k<j1;k++) 

printf("%d",b1[k]);

 printf(" "); 

for(k=0;k<8;k++) 

printf("%d",f[k]);

printf("\n\n Do u want to continue?");

ch=getch();

}

while(ch=='y' || ch=='Y'); 

getch();

}


INPUT/OUTPUT:


Enter the bit string (space for each byte) 11111111 01111110 00111110


After stuffing : 00000011 01111110 111110111011111010001111100 01111110


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M