Decode custom_mode Flightmode bitmask

“custom_mode” seems to be a bitmask.
Which informations does it include but the flightmodes?
How can the flightmode be calculated?