Bit masking is the stuff seen in calls to certain DirectX functions and many other functions in many libraries. Function( Something | something else | something other ). The enum values must be powers of 2 or masking will fail. Take 10 and 101, OR them together -> 111. Now try and use bit masking with 100. 100 AND 111 -> 100. So we are getting a false positive because 100 or 4 is not a power of 2. One way to easily enter this into enums is to do 0, 1 << 0, 1 << 1, 1 << 2, etc. This shifts the 1 bit over by the number on the right, giving a power of 2 value and a relatively clear and readable way to generate values usable for masking. Library here for typesafe bitwise ops based on enums.
18 November 2009