Definitely not an expert but my take away from my limited experience with bit masks are like this:
Bitmasks can help abstraction by not exposing the object(s) being set.
They are helpful for setting on/off switches for an undeterminate number of sources with undeterminate names.
They also help toggling or setting a large or undeterminate number of switches with a single operation.
They are helpful to store various preset configuration values for a large or undeterminate number of switches in single variables.
For example you can have presets like admin = 24; user = 17; poweruser = 31;. And just set config = admin and you are good to go rather than assigning many variables.
Another example, bit masks are used in Unity 3D engine to set the layers a Camera renders in runtime. Unity has two parts, an editor where you set things using GUI, and your code. Layer count and names are customized in the Unity editor. And in your camera code, instead of using a whole list of exposed layer objects, you can provide a bit mask to modify which layers are rendered with that particular camera.
Definitely not an expert but my take away from my limited experience with bit masks are like this:
For example you can have presets like
admin = 24; user = 17; poweruser = 31;
. And just setconfig = admin
and you are good to go rather than assigning many variables.Another example, bit masks are used in Unity 3D engine to set the layers a Camera renders in runtime. Unity has two parts, an editor where you set things using GUI, and your code. Layer count and names are customized in the Unity editor. And in your camera code, instead of using a whole list of exposed layer objects, you can provide a bit mask to modify which layers are rendered with that particular camera.
Yeah, I also have very limited experience with bitmasks myself. Seems like bitmasking isn't as impractical as I initially thought. Thanks for sharing!