Wednesday, 8 March 2017

What is Bit Stuffing and Destuffing ?

In data transmission and telecommunication, bit stuffing (also known—uncommonly—as positive justification) is the insertion of non information bits into data. Stuffed bits should not be confused with overhead bits. The opposite is called destuffing.
Only text ;
 Flag is any char. not used in text
 But any pattern used for flag can also be part of the
information
 The receiver will encounter this pattern in the
middle of the data, assume it as the end of frame.
 To fix this Byte stuffing strategy was added.
Byte stuffing
 A special byte is added to the data section of the
frame when there is character with the same pattern
as the flag.
 The data section is stuffed with a extra byte
 This byte is usually called the escape character
(ESC), which has a predefined bit pattern.
 When encountered remove it from data
 Treat the next character as data , not as flag
fig1
Byte stuffing is the process of adding 1 extra byte whenever there is a flag or escape character in the text.
 The data section of a frame is a sequence of bits to be
interpreted by the upper layer as text, audio etc.
 In addition to header and trailers there is a need for
delimiter to separate one frame from the other.
 Special 8 bit pattern flag 0111 1110 as delimiter
 Same type of problem.
 Not the end of frame.
Stuffing 1 bit (instead of 1 byte) to prevent the
pattern from looking like a flag.
 This strategy is called bit stuffing
 In bit stuffing, if a 0 and five consecutive 1 bits are
encountered, an extra 0 is added
 This extra stuffed bit is eventually removed from the
data by the receiver.
 This guarantees that the flag field sequence does not
appear in the frame
fig2
Bit stuffing is the process of adding one extra 0 whenever five consecutive 1s follow a 0 in the data, so that the receiver does not mistake the pattern 0111110 for a flag.
fig3
C Program To Find Bit Stuffing And Destuffing In C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *p,*q;
char temp;
char in[100];
char stuff[100];
char destuff[100];
int count=0;
printf("enter the input character string (0‘s & 1‘s only):\n");
scanf("%s",in);
p=in;
q=stuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='0';
q++;
}
count=0;
}
}
*q='\0';
printf("\nthe stuffed character string is");
printf("\n%s",stuff);
p=stuff;
q=destuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nthe destuffed character string is");
printf("\n%s\n",destuff);
return 0;
}
OUTPUT:
bitstuff

REFERENCES:

No comments:

Post a Comment