implement shift-or algorithm