A clarification: this isn't to say such tricks are never used in a non-toy environment. There is, for example, this search algorithm I made for a serious purpose:
https://stackoverflow.com/q/40141793/1763356
The bit math is milder, but it still comes in handy.
https://www.reddit.com/r/programming/comments/4vctor/.../d5x...
https://cs.stackexchange.com/a/74888/16408
The first asked
> Extra-extra credit can be earned for finding an algorithm that takes no more than O(log N) space and no more than O(log N) time, where N is the number you are seeking for.
and the bit magic made it O(1) space and time. The second was on similar lines.
Unfortunately the bit fiddling at my day job tends to be a bit tamer ;).