Q:

How to encode 4B/5B

In encoding 4B5B, the rule  is no more than one leading zero and no more than two trailing zeros. For example, to convert 1110, the result is  11100; just add zero to end.
To convert 0101, I thought the result should be 01010 because only one leading zero and no more than two trailing zeros.
However, the correct result is 01011. Why is that?

A:

The nibble 0101 can't be converted to 01010 because that's what 0100 converts to. Before you ask why 0100 doesn't convert to 01001, it's because 0001 converts to 01001.
The nibbles are converted from a dictionary, and the dictionary specifies that 0101 converts to 01011. Encoding and decoding by a dictionary is fast and easy, which is appealing when designing communications systems.

