11-05-2022 01:41 PM - edited 11-05-2022 02:33 PM
Hey all, I'm new to LabVIEW and have what I think is a pretty straightforward question.
Basically I have 8 outputs, each a single scalar value. I expect 6 of the outputs to be ~0 and the other 2 to be some positive value, and which combination is non-zero signifies some arbitrary thing which I would like to identify i.e. if 1&2 > 0, then A, 1&3 > 0, then B, .... if 7&8 > 0, then _. So that is 36 possible combinations/outcomes total (8+7+6+5+4+3+2+1). If >2 or <2 outputs are non-zero, I would like to ignore.
I assume the first step is to run each output into a 'greater than' comparator, but I'm not sure where to go from there except a complex system of booleans. Does anyone know a better way to accomplish this? Thanks for reading!
Solved! Go to Solution.
11-05-2022 03:26 PM - edited 11-05-2022 03:40 PM
You can convert the array of 8 Booleans to a scalar integer (one bit per Boolean) and use it to index into a lookup table containing all possible 256 cases.
Now sure what prevents you from having more than 36 28 cases. Can you always guarantee that only two booleans are TRUE and all other false under all conditions? What if none are TRUE? What if 1&2&6 are TRUE?
(Note that there are only 28 possibilities of picking any two from eight (7+6+5+4+3+2+1)).
You cannot "ignore" (your words) a case, but you can initiate special handling. You can fill the lookup table with a sentinel value for all cases that should not occur (e.g. empty string, "ERROR", or similar) and proceed accordingly.
Also be aware that equal comparisons with floating point values can be tricky. What' the definition of ~0?
11-05-2022 04:11 PM
See if this can give you some ideas (using a map with a boolean array as key and a string as value).
11-05-2022 05:34 PM
This looks like exactly what I need, thank you so much!