I'm trying to record the state of some pins over time. To save memory, I'm thinking about encoding the pin states into a single integer, like this:
Pin 1: TRUE
Pin 2: FALSE
Pin 3: FALSE
Pin 4: TRUE
Pin 1 = 1, Pin 2 = 2, Pin 3 = 4, Pin 4 = 8
1 + 0 + 0 + 8
Result: 9
This is pretty efficient. But how do I decode the pin states from this best? Or do you recommend a better way to do this?