User define button functions efficiency/methodology advice request.

Hi everyone, this is my first time posting, and wanted to thank you all so much for all the effort and time spent answering questions. This forum has been a life line many many times for me, and this is the first time I couldn't find the answer to my question already covered in a post. Likely because of a misunderstanding of something on my part, likely correct terminology.

I have 4 switches that I would like to use to control 8 LEDs. The LEDs controlled by each switch I would like be user defined, via an LCD menu. The user would be able to set any number of leds to switch 1, 2, 3, 4. One LED controlled by multiple switches isnt a concern, so there is no need to remove them from the pool or anything like that.

I have come up with a solution that would likely work, but its so inelegant and inefficient that there has to be a better way. Assigning a variable for each switch to each LED. Something like this:

if (switch1 == HIGH){
       if (sw1LED1 == true){digital.Write(LED1, HIGH);}
       if (sw1LED2 == true){digital.Write(LED2, HIGH);}

etc...
Not only is that just awful, it would require 32 variables.

I second thought was, 8 LEDs, 8 bits in a byte, maybe I could use each bit to indicate if an LED should be on or off and only use 4 bytes. I know I can see a byte with use of BIN, but Im not at all sure how to use a comparative statement for a single bit of a byte, or how even single one out to compare. Actually that encompasses the totality of my understanding of BIN.

If anyone could point me to some reading or suggest a less clumsy way to go about this, it would be fantastic. Thank you very much for all the help.

you could use bitwise operators to manipulate bits in a byte or bitfields

Im not at all sure how to use a comparative statement for a single bit of a byte, or how even single one out to compare

Have a look at the bitWrite(), bitRead() and other associated functions in the Arduino reference.

There are other methods to read and write individual bits of a variable using bit masking techniques but start with the easy to use functions.

Thank you so much!! Looks like I have plenty to fall down the rabbit hole with here. You guys are awesome.

although you can save data space by using individual bits and manipulating them you may find the code ends up larger than the data space saved
it can end up a choice of saving data space or code space or even run time or clarity of code