Combine Bitflags

Viewed 544

I have several flags:

    None = 0
    HR = 1
    HD = 2,
    DT = 4,
    Fl = 8
..

etc

I want to create a function where I input a certain flag, lets say : 6.

Returned should be HDDT, since 2 | 4 = 6. It can also happen that 3 or more flags are combined or just a single one. e.g. : 7 = 1 | 2 | 4 => HRHDDT.

How can I return the concated string depending on the flag value?

In my case the enum has many more entries, which would make a simple if statement really uncomfortable, because I would have to cover hundreds of cases.

Is there any clever solution to this?

2 Answers
Related