I have a bit shifting enum:
typdef enum:{
TypeA = 1 << 0,
TypeB = 1 << 1,
TypeC = 1 << 2,
TypeD = 1 << 3
} my_type_t
And I was trying to determine the highest level it's in of a value, for example, 7
would be equivalent to TypeC
, using a switch statement. For example:
NSString* stringType(NSUInteger value){
switch (value){
case (TypeA):{
return @"TypeA";
}
case (TypeA | TypeB):{
return @"TypeB";
}
case (TypeA | TypeB | TypeC):{
return @"TypeC";
}
case (TypeA | TypeB | TypeC | TypeD):{
return @"TypeD";
}
default:
return @"Unknown"
}
}
but I always got Unknown
value, any idea why and how to fix this?