If you're interested in learning more:
* Check out libdivide: http://libdivide.com/
* Also, the awesome book "Hacker's Delight" has extensive information about how and why these tricks work. It's the bit-twiddling bible -- probably my favorite programming book I've ever read