We all know that bit masking is occasionally necessary if you're dealing with data at the binary level but, if you're anything like me, you use it infrequently enough that you constantly have to lookup anything beyond the basics. This is just a spot to record all of the little tricks that I've come across in one place.
The three most common operations are to get, set and clear single bits. Those are usually pretty easy to remember but for thoroughness I'll note them down here.
# Get a bit
mask = (1<<bit)
num & mask