See programming-idioms.org:
Another version showing more results using wrap-around, saturating and overflow-checking versions: