Hi everybody. I've been trying to emulate in C# a behavior which I was implementing without any problems in C++. I have a flag collection, which based on powers of 2, and a flag which I need to check if it exists in the collection.
byte flagCollection = 1 | 2 | 4 | 8;
byte flag = 2;
if ((flagCollection & flag) != 0) MessageBox.Show("y"); else MessageBox.Show("n");
Now, the problem is that whatever I set Flag to (2, 3, 100, 211), I always get "y", except for 0. Of course, 1, 2, 4, 8 would be some constants which have various meanings in my application.
In C++:
if (flagCollection & flag)
Would result in TRUE for the variables above.