implementation of Right-to-left binary method