Clever Uses for Bitmasks
I'm looking for interesting and clever uses of bitmasks. I've commonly seen them used to store collections of flags (thanks to K&R, and Rochkind), but I'd like to see examples of other clever uses. 

For example, I once heard of someone storing a chessboard in a 64 bit integer, and bitmasking it to get certain pieces of information. Thinking of it now, I don't think you can do that much with this representation, because at best you could store vacancy of a square, not which piece it is. I don't recall exactly what this person was using the structure for, but I can imagine others have seen similarly clever uses for bitmasks.

I realize this should be a community wiki but I don't know how to set that.
Clever Uses for Bitmasks
===

I'm looking for interesting and clever uses of bitmasks. I've commonly seen them used to store collections of flags (thanks to K&R, and Rochkind), but I'd like to see examples of other clever uses. 

For example, I once heard of someone storing a chessboard in a 64 bit integer, and bitmasking it to get certain pieces of information. Thinking of it now, I don't think you can do that much with this representation, because at best you could store vacancy of a square, not which piece it is. I don't recall exactly what this person was using the structure for, but I can imagine others have seen similarly clever uses for bitmasks.

I realize this should be a community wiki but I don't know how to set that.