I'm not sure how to go about solving this.
I have a byte of data that is received that defines which colour LEDs are available in a piece of hardware.
There are 4 LEDs Red, Green, Blue and White.
bit 0 = Red (1 On | 0 Off)
bit 1 = Green (1 On | 0 Off)
bit 2 = Blue (1 On | 0 Off)
bit 3 = White (1 On | 0 Off)
bit 4 = Unused / Future Use
bit 5 = Unused / Future Use
bit 6 = Unused / Future Use
bit 7 = Unused / Future Use
If I get an int value 11 from the hardware the bit mask is: 0000 1011 (Little Endian) so the LEDs in use are White, Green and Red.
If I got an int value 15 then all LEDs are in use, if it is 7 all but white are in use.
What I'm trying to work out is a good way to evaluate the bits that are set and then display which LEDs are available.
What is the best way to evaluate which bits are set and then display it in NSString to the user.
Should I use an enum as below and then try to evaluate that, how would I do the evaluation?
typedef enum {
RedLEDAvailable = 1 << 0,
GreenLEDAvailable = 1 << 1,
BlueLEDAvailable = 1 << 2,
WhiteLEDAvailable = 1 << 3
} LEDStatus;
Thanks in advance.