Yes, that's the one. Your solution is neater than mine because it avoids the number variables, and possibly faster (though I can't be bothered to benchmark it), but mine has a small advantage in that you can use it with modifiers such as /i, /g, and /x.