Main menu

Pages

Difference Between Bit and Byte - stuffing examples

Difference Between Bit and Byte - stuffing examples, The data link layer is responsible for something called a frame, which is the division of the stream of bits from the network layer into controllable units called frames. Acknowledgment of the receipt.


Difference Between Bit and Byte



The basics of the difference between Byte stuffing and Bit stuffing


Frames can be either fixed size or variable size, where in fixed-size frames there is no need to set frame boundaries, the same size can be used to define the end of a frame and the beginning of the next frame. but in variable size frames, a way is needed to define the end of the frame and the beginning of the frame next frame.


To separate one frame from the next an “8-bit” or “1 byte” flag is added at the beginning and end of the frame. but the problem with that is that any pattern used for the flag can also be part of the information, so there are two ways around this problem:


First: What is Byte stuffing?


Byte stuffing: A mechanism for converting a message consisting of a string of bytes that may contain reserved values such as a frame selector, into another byte sequence that does not contain the reserved values.


Second: What is Bit stuffing?


Bit stuffing is a mechanism for inserting one or more bits of non-information into a message to be sent to break up the message sequence and for the purpose of synchronization.


How to do Byte stuffing and Bit stuffing


A byte and usually an "ESC" escape character that has a predefined bit pattern are incremented to the data section of the frame when there is a character with the same flag pattern. where when the receiver encounters an "ESC" character it removes it from the data section and treats the next character as data and not Marker.


But the problem arises when the text contains one or more escape characters followed by a sign, and to solve this problem, the escape characters that are part of the text are distinguished by another escape character, that is, if the escape character is part of the text, an additional character is added to show that the second character is part of the text.


In the data link layer, the bit stream from the physical layer is divided into data frames, where the data frames can be of fixed length or variable length. And in frames of variable length, the size of each transmitted frame may vary, so the bit pattern is used as a delimiter to mark the end of frame one and the beginning of the next frame. However, if the pattern occurs in the message, then the mechanisms must be combined so that this situation is avoided. The two common approaches are:


  • byte-stuffing, where the byte in the message is padded to distinguish from the delimiter, is also called character-oriented framing.
  • Bit stuffing, where a pattern of bits of arbitrary length is stuffed into the message to distinguish from the delimiter is also called bit-framing.


Note:

"ESC" is an abbreviation for "Electronic Stability Control".


Data link layer frameworks in Byte stuffing and Bit stuffing


First: the head of the frame


Contains the source and destination addresses of the frame.


Second: payload field


  • Contains the message to be delivered.
  • In “Bit stuffing” it is a variable sequence of bits, while in “Byte stuffing” it is a variable sequence of data bytes.


Third: the trailer


Contains error detection and debugging bits.


Fourth: flags


Flags: They are frame specifiers that indicate the start and end of the frame. In “Bit stuffing” the flag consists of a bit pattern that specifies the start and end bits, and it generally consists of “8 bits” and consists of six or more consecutive “1s”. while in “ Byte stuffing” The flag consists of “1 byte” to denote a special character that depends on the protocol.


The difference between Byte stuffing and Bit stuffing


1- Byte stuffing mechanism


  • If the flag byte pattern is present in the message byte sequence, there must be a strategy so that the receiver does not consider the pattern as the end of the frame.
  • A special byte called an "ESC" escape character is stuffed before each byte in the message in the same pattern as the flag byte.
  • If an 'ESC' sequence is found in a message byte, another 'ESC' byte will be stuffed before it.


2- The mechanism of Bit stuffing


  • A determinant sequence generally contains six or more consecutive "1s".
  • Most protocols use the “8-bit” form i.e. “01111110” as a flag.
  • In order to distinguish between a message and a tag in the same state of the sequence, a single bit is stuffed into the message.
  • When five consecutive "0 bits" are followed by "0 bits" in the message, an additional "0 bit" is stuffed at the end of the five ones.
  • When the receiver receives the message, it removes the zeros padded after each sequence of five "1s".
  • Then the unpadded message is sent to the upper layers.
  • The flag is mostly a special "8-bit" pattern i.e. "01111110" used to identify the start and end of a frame.
  • The flag problem is the same as it was in the case of "Byte stuffing", so in this protocol what is done is if there are 0 and five single bits in a row, an extra 0 is added after those bits.
  • This extra padded bit of data is removed by the receiver.
  • The extra bit is added after one “0” followed by five single bits regardless of the value of the next bit.
  • Also, since the sender side always knows which sequence represents the data and which flag, it will only add this extra bit into the data sequence, not into the flag sequence.


Bit stuffing features


  • Allows the frame to contain a random number of bits and a random character size.
  • The tires are separated by a separate flag.
  • Each frame begins and ends with a special bit pattern, called the "01111110 byte" flag.
  • When five consecutive "1s" are encountered in the data, it automatically stuffs the "0" bit into the outgoing bit stream.
  • In this method frames contain a random number of bits and allow character codes with a random number of bits per character, in which case each frame starts and ends with a special bit pattern “01111110”.
  • In data, "0 bits" are automatically stuffed into the outgoing bit stream when the sender's data link layer finds five consecutive seconds.
  • Bit-stuffing is similar to byte-stuffing, where the escape byte in the outgoing character stream is stuffed before the flag byte in the data.
  • When the receiver sees five consecutive bits coming in followed by a "0 bit", it automatically removes any "0 bit" deletes, and Bit Stuffing is completely transparent to the network layer as byte-stuffing.
  • This framing method finds its application in networks where changing the data to a symbol on the physical medium contains some redundant or redundant data, for example some LANs encode part of the data using two physical bits.