I have an enmeration with a set of values which can be bitwise or'd together:
enum EventType_e { EventType_PING = 1, EventType_PANG = 2, EventType_PONG = 4, EventType_PUNG = 8 }; I expect this enumeration to grow to contain at most 15-20 items. On receiving one of these enumerated values I would like to be able to map it to a vector, but instead of having a sparse array I'd like to collapse the values down. What is the best way of mapping 1,2,4,8,16,32 to 1,2,3,4,5,6 (i.e. finding 'x' in 2^x=1, 2^x=2, 2^x=4, 2^x=8, etc.)