Encode your bits
Conventions follow Forouzan: NRZ-L 0 = high; Manchester 0 = high→low; differential Manchester inverts at the start of a 0; AMI alternates the 1s; 2B1Q 00=−3, 01=−1, 10=+3, 11=+1.
4 bits in, 5 bits out
Longest run of 0s afterOverhead25% (5 bits per 4)No 5-bit code has more than one leading 0 or more than two trailing 0s, so the coded stream never has more than three 0s in a row. NRZ-I then always has a transition at least every 4 bits.
Replace long runs of 0s
B8ZS: eight 0s become 000VB0VB. HDB3: four 0s become 000V if the number of 1s since the last substitution is odd, or B00V if it is even. V repeats the previous pulse's polarity, breaking the AMI rule on purpose so the receiver can spot and undo it.