CS FundamentalsVery hardProduct company interview · GATE level

An HDLC-style link uses the flag 01111110 and bit stuffing: the sender inserts a 0 after every run of five consecutive 1s in the data. The 27-bit data field 011111011111101111110011111 is to be sent. How many bits are transmitted between the opening and closing flags?

  1. A. 29 bits
  2. B. 30 bits
  3. C. 31 bits
  4. D. 28 bits

Correct answer: C. 31 bits

A 0 is stuffed after every five consecutive 1s, whatever the next data bit is. The data has runs of 5, 6, 6 and 5 ones. Each run gets exactly one stuffed 0 (in a run of six, the count restarts after the stuffed 0, and the single remaining 1 does not reach five). That is 4 stuffed bits: 0111110011111010111110100111110, so 27 + 4 = 31 bits. Stuffing only where a sixth 1 actually follows gives 29; skipping the run at the very end gives 30 - but without that last 0, the data's final 11111 followed by the flag's leading 0 would be safe only by luck, and the rule is applied mechanically.

More Computer Networks questions

Exams that ask this topic