04 Try it yourself Interactive

Stuff one payload, then unstuff it and check it came back

The payload is fourteen bits, 01111110011010, and it was chosen for one reason: its first eight bits are the flag pattern. Sent raw it would close the frame six bits early and the receiver would throw the rest away. Sender walks the fourteen bits one at a time, counting consecutive 1s, and when the count reaches five it inserts a 0 and resets, producing the fifteen bits 011111010011010. Receiver walks those fifteen bits with the same counter and removes the 0 that follows five 1s. The last step of the receiver run puts the recovered bits and the original side by side and compares them in code, not in prose. Nothing plays on its own: Next, Back and Reset, or the arrow keys.

Sender · stuffing the payload
payload 14 bits, nothing sent yet
Indigo is the two 8-bit flags. Amber is the bit being read now, with the current run of 1s tinted behind it. Green is a bit the sender inserted. Rose is a bit the receiver removed. Grey has not been reached yet.
Press Next to begin. Each press moves the pointer one bit.


      
Bits scanned
Consecutive 1s
Bits stuffed0
Output length0
step 0 / 0