Enumerations allow you to name different related options. The names can refer to a single option or you can use what you now know about bits to combine them into flags. With flags, you can have multiple enumeration options that you can work with as a single value.

Whether you want to keep track of colors with enumeration values red, green, blue, etc. or you want to keep track of what a piece of armor is made out of as this episode describes, enumerations allow you to provide more meaningful names to these values.

It’s a lot more readable and less error prone than returning an integer directly and then trying to remember what value that integer represents. Give your values actual names with an enumeration.

Enumerations declared like this can only take on a single value at a time. In other words, the color can be either red, or it can be blue, etc. But it can’t be both red and blue.

At least not with a simple enumeration. If you instead carefully choose the numeric values for each value name so that the numeric values don’t conflict with one another at the binary level, then they can be combined.

This is called a flag based enumeration and the enumeration values themselves are called flags. You choose values so they each have a single 1 binary digit and make sure that each flag value uses a different binary digit. You’ll want to use powers of two since these are the values that align with the binary place holder positions.

Should your first flag be given the value of zero? Well, only if you want or need to be able to express the concept that none of the other flags currently apply. That could be important and if so, you probably want to consider naming this value “none” or “empty” or something that conveys the meaning of an absence of a value.

You might also want to define enumeration values that are not intended to be used as flags but as a mask in case you need to work with certain groups of flags. Maybe certain flag combinations have special meaning or you just want to categorize them. The episode explains more about this.