Bit Stuffing Program in C

Bit Stuffing Program in C

Here, you will learn about Bit Stuffing and get the example code of the Bit Stuffing Program in C programming language.

bit stuffing program in c

What is Bit Stuffing

The Bit stuffing method is used in data communication to enable reliable and accurate data delivery between devices. It is used to identify flag characters or data that have been corrupted or lost. This is also called bit-oriented framing.

Bit stuffing is used in various networking protocols, such as HDLC (High-level Data Link Control), to ensure reliable data transmission.

osi model

 

for example, it allow the start and end of a frame to be recognized. The Data Link layer of the OSI Model(Open Systems Interconnection model) breaks a stream of bits into more manageable units, called frames. Each frame contains information about who is sending and receiving it, to help with the transmission.
bit transmission error detection

 

An 8-bit flag byte is included at the beginning and end of the sequence of frames to prevent the receiver from misstating the flag as part of the sent information. Bit stuffing can also have other purposes; for example, it can help the receiver identify the start and end of a frame.

Algorithm of Bit Stuffing

Step 1: Start the program.

Step 2: Include all the header files.

Step 3: Declare two file pointers so that the input and output files may be opened in read-only and write-only, respectively.

Step 4: Read contents from input file.

Step 5: If the bit is 1, look for four consecutive ones.

Step 6: If so, insert a bit 0 there (i.e., after five consecutive 1s).

Step 7: Open the output file, then print the string that has been stuffed.

Step 8: End the program.

Example Code of Bit Stuffing Program in C

Output :-

Enter a String: 01101111110111110

String after Bit Stuffing is perfumed: 0111111001101111101101111101001111110

String after De-Stuffing is performed: 0110111111101111110

Other Related Programs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top