I agree with @Steve-Mcl . This whole code takes max 1000 CPU cycles to run.
(at 1GHz > that is 0.001 ms)
But a good programmer always optimising everything
You can store min. 31 True/False values safely in 1 number. (No need of Arrays)
I recommend these bit manipulation functions wrote by @Steve-Mcl :
Node-red-contrib-mcp23017chip - #71 by Steve-Mcl