I have situation like this:
got enum
enum MyType{
None = 0,
First = 1,
Second = 2,
Third = 4,
//and so on
}
now I wan't to check if given number is result of the sum of the binary for example
int givenNumber = 3;
int result =
//how to get that it's sum of 2 enums in this particular case would be (int)Type.First & (int)Type.Second == 3;
Hope that my question is clear enough and someone can help with this.
Edit
enum values are always powered by 2
I want to write a method which should check that given number can be one pice of different binary sum example:
int givenNumber = 1; //1 , 3 ,5 and 7 will be the answer
- Real life sample: I got contractors in my db and every contractor can be Producer = 1,Supplier = 2,Service = 4 in db I can store only 1 value int in this case would be smartest choice. When I loading Items to my combobox of Service - Contractors I want load every row which have for example value 4 or 5 or 7 (beacuse 7 = 1+2+4, 5 = 1+4 and 4=4).
Is now my question more clear?