How Line Coding Visualizer works
Line coding turns a bit stream into a voltage waveform, and the schemes differ in what they optimise for. Unipolar NRZ uses zero and a positive level, which is simple but leaves a large DC component. Polar NRZ-L maps 0 and 1 to opposite levels; NRZ-I instead signals a 1 by inverting the current level and a 0 by holding it, so it survives swapped wires. Both suffer at long runs of identical bits because the receiver has no edge to lock its clock to. Manchester fixes that by putting a transition in the middle of every bit — low-to-high for one value, high-to-low for the other — which makes the signal self-clocking at the price of double the bandwidth. Differential Manchester keeps the mid-bit transition for timing and encodes data as the presence or absence of a transition at the bit boundary. Bipolar AMI leaves 0 at zero volts and alternates each 1 between +V and −V, cancelling DC, but long strings of zeros still starve the clock. B8ZS and HDB3 are AMI with a scrambling rule: they replace a run of zeros with a pattern containing deliberate bipolar violations that the receiver recognises and reverses.
Pseudocode
// Polar NRZ-L: level carries the bit
nrzL(bits): for b in bits: emit(b == 1 ? +V : -V)
// Polar NRZ-I: a 1 inverts, a 0 holds
nrzI(bits):
level = -V
for b in bits:
if b == 1: level = -level
emit(level) // one level per bit period
// Manchester: mid-bit transition always present
manchester(bits):
for b in bits:
if b == 1: emit(-V, +V) // low then high, half a bit each
else: emit(+V, -V)
// Bipolar AMI: zeros idle, ones alternate polarity
ami(bits):
lastPolarity = -V
for b in bits:
if b == 0: emit(0)
else:
lastPolarity = -lastPolarity
emit(lastPolarity)
// B8ZS: replace eight consecutive zeros (V = violation, B = normal pulse)
// if last pulse was positive: 0 0 0 V B 0 V B -> 0 0 0 + - 0 - +
// if last pulse was negative: 0 0 0 V B 0 V B -> 0 0 0 - + 0 + -
// HDB3: replace four consecutive zeros, choosing by pulse count since
// the last substitution, so that the DC balance is preserved
// odd number of ones since last substitution: 0 0 0 V
// even number of ones since last substitution: B 0 0 VTime and space complexity
- Time
- O(n) in the number of bits
- Space
- O(n) for the emitted waveform samples
Every scheme is a single left-to-right pass carrying at most a small amount of state — the last polarity for AMI, a zero-run counter for B8ZS and HDB3.
Worked example
Encode the bit stream 0 1 0 0 1 1 with Bipolar AMI, assuming the previous pulse was negative.
- Bit 0Zero → hold 0 V. Last polarity still −V.
- Bit 1One → invert from −V, so emit +V. Last polarity = +V.
- Bit 0Zero → 0 V, polarity unchanged.
- Bit 0Zero → 0 V, polarity unchanged.
- Bit 1One → invert from +V, so emit −V.
- Bit 1One → invert from −V, so emit +V.
Waveform: 0, +V, 0, 0, −V, +V. The ones alternate strictly, so the average voltage is zero — but the two zeros in the middle produced no transitions, which is exactly the clock-recovery gap B8ZS and HDB3 exist to close.
Common exam mistakes
- Mixing up NRZ-L and NRZ-I. NRZ-L encodes the bit in the level itself; NRZ-I encodes a 1 as a change of level and a 0 as no change.
- Drawing Manchester with the transition at the bit boundary. The defining transition is at the middle of the bit period; boundary transitions only appear when consecutive bits require them.
- Treating AMI zeros as a voltage. A zero is no signal at all, not the negative level.
- Forgetting that B8ZS and HDB3 substitutions deliberately violate the alternation rule. The bipolar violation is the signal to the receiver — a "correct" alternating pattern would be undetectable.
- Applying HDB3's parity rule without tracking ones since the last substitution. Choosing 000V versus B00V by the wrong parity destroys the DC balance the scheme exists to maintain.
Frequently asked questions
Why is Manchester encoding called self-clocking?
Every bit period contains a guaranteed mid-bit transition, so the receiver can recover timing from the signal itself no matter how long a run of identical bits lasts. That is why classic Ethernet used it.
What problem do B8ZS and HDB3 solve that AMI does not?
Long runs of zeros. AMI emits nothing for a zero, so a long zero run gives the receiver no transitions to synchronise on. B8ZS (eight zeros, used in North America) and HDB3 (four zeros, used in Europe and Japan) substitute a recognisable pattern containing bipolar violations to force transitions.
Why does a DC component matter?
Transformers and capacitively coupled circuits cannot pass DC, so a scheme with a non-zero average voltage suffers baseline wander over such links. AMI and Manchester are DC-balanced; unipolar NRZ is not.
Which scheme uses the most bandwidth?
Manchester and Differential Manchester — the mid-bit transition means the signal can change twice per bit, so the required bandwidth is roughly double that of NRZ for the same data rate.
Related simulators
Number System Converter
Convert between binary, octal, decimal and hex with every division and remainder shown.
Number System Operations
Add, subtract and complement in any base, carries and borrows worked out in place.
Logic Gate Circuit Builder
Type a boolean expression and get its truth table, K-map and minimal SOP, derived step by step.
DFA Simulator
Fill in your own transition table, then step a string through it and see it accept or reject.