Data is encapsulated in frames in the data link layer and sent over the network. Bit Stuffing is a error detection technique.
The idea used is very simple. Each frame begins and ends with a special bit pattern “01111110” which is the flag byte. Whenever the sender’s data link layer encounters five consecutive 1s in the data, it automatically stuffs a 0 bit in the outgoing bit stream. The bit stuffing is analogous to byte stuffing, in which an escape byte is stuffed into the ongoing character stream before a flag byte in the data.
When the receiver sees five consecutive 1 bits, followed by a 0 bit, it automatically destuffs(deletes) the 0 bit. Bit stuffing is completely transparent to the network layer in both sender and receiver computers.
With bit stuffing, the boundary between the two frames can be unambiguously recognized by the flag pattern. Thus, if the receiver loses track of where it is, all it has to do is scan the input for flag sequences., since they can only occur at frame boundaries and never within the data.
Illustrative Examples Sender Side(Client): User enters a binary data as input. Enter data: 0000001 Data is stuffed and sent to the reciever for unstuffing. Here server is the receiver. Data stuffed in client: 01111110000000101111110 Sending to server for unstuffing Receiver Side(Server): Receiver receives the stuffed data. Stuffed data from client: 01111110000000101111110 Reciever has to unstuff the input data from sender and get the original data which was given as input by the user. Unstuffed data: 0000001
The code implementation of the above logic is given below.
At Sender side(client side):
At Receiver side(server side):
The input and output are as shown above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Difference between Byte stuffing and Bit stuffing
- Bit Stuffing in Computer Network
- Difference between Substitution Cipher Technique and Transposition Cipher Technique
- Implementing Byte Stuffing using Java
- Error Detection in Computer Networks
- Error Detection Code - Checksum
- LZW (Lempel–Ziv–Welch) Compression technique
- Voice Biometric Technique in Network Security
- How to create a Face Detection Android App using Machine Learning KIT on Firebase
- Image Processing in Java | Set 9 ( Face Detection )
- Collision Detection in CSMA/CD
- Intrusion Detection System (IDS)
- Approaches to Intrusion Detection and Prevention
- Method overloading and null error in Java
- Unreachable Code Error in Java
- Error Control in TCP
- Forward Error Correction in Computer Networks
- Difference between Flow Control and Error Control
- Error Control in Data Link Layer
- How to download and install Java for 64 bit machine
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.