Encode & decode boolean values into a single integer?
You are almost there with that. Personally I'd use OR not +:

This is a better way of defining the pins instead of using 1, 2, 4 etc. It results in the same thing, but you can see the bit number in there. The &lt;&lt; is left shift.

#define PIN0 (1 &lt;&lt; 0)
#define PIN1 (1 &lt;&lt; 1)
#define PIN2 (1 &lt;&lt; 2)
#define PIN3 (1 &lt;&lt; 4)


Now you can combine:

uint8_t val = PIN0 | PIN3; // 9


And you can check if one is set:

if (val &amp; PIN3) {
    // ....
}


To loop through the pins you can use the &lt;&lt; again:

for (uint8_t pin = 0; pin &lt; 8; pin++) {
    if (val &amp; (1 &lt;&lt; pin)) {
        // ....
    }
}


etc.