Shift-and-add algorithm