Common Uses
Find out the common uses of bit operations.
Flags
Flags are single-bit independent data that are kept together in the same variable. As they are only one bit wide each, they are suitable for representing binary concepts like enabled/disabled, valid/invalid, etc.
We sometimes encounter such one-bit concepts in D modules that are based on C libraries.
Flags are usually defined as non-overlapping values of an enum type.
As an example, let’s consider a car racing game where the realism of the game is configurable:
-
The fuel consumption is realistic or not.
-
Collisions can damage the cars or not. ...