Bi-directional encoder implementation.