In my model I'm receiving a property that's an integer composed of bit flags denoting access to a set of facilities. So, if the objects has A, B, D but lacks C, the code for it would be 7 (1 + 2 + 0 + 4).
In the table I'm generating, I prefer to present it as a bunch of columns with "Y" if the corresponding facility's present in each individual object's information.
But when typed a pattern emerged, as follows.
<td>
@if ((station.Facility & 1) == 1) {<span>yes</span>}
</td>
<td>
@if ((station.Facility & 2) == 2) {<span>yes</span>}
</td>
...
<td>
@if ((station.Facility & 1024) == 1024) {<span>yes</span>}
</td>
Any half-lousy excuse to a code monkey feels that there should be much fewer lines here because we should repeat
<td>
@if ((station.Facility & bit) == bit) {<span>yes</span>}
</td>
except for the tiny bit that's pooping through the powers of 2. Me being a bit DUI (developing under influence) because of the 2016 just starting, might be the reason why I can't see how to do that.
Nevertheless - how do I do that?
Also, I also have a suspicion that the conditional expression may be simplified, as there are nested parenthesis present right now. I was surprised that AND (& operator) bound weaker than equality (== operator) but that's how I solved it. I've considered using shifting (<< operator) but the syntax got actually more complex and given that the speed isn't exactly an issue, I don't have to use it (unless it's simplifying the code).
Is there a smoother way to achieve that?