11-02-2016 04:34 PM
Thats what "Boolean to 0 1" and "Boolean Array to Number" are for 😉
11-02-2016 05:44 PM - edited 11-02-2016 05:45 PM
I like LabVIEW a lot, but this is one of the areas where the text code solution is more straightforward and readable than most LabVIEW solutions. You might think GreyGrey's suggestion isn't elegant, but most alternatives are likely to be considerably worse.
The main exception I can think of is to "cheat" and use a LabVIEW formula node that accepts a limited syntax of text code.
P.S. Started the answer above, called pulled away, returning hours later. Jeff B's solution is essentially similar to the one described by GreyGrey. Either is a fairly readable solution to your very specific problem. GreyGrey's string-based solution would extend more naturally to a large number of variables. But both very much depend on the fact that all the logical operators are AND's.
For your specific problem full of nothing but AND's, both are fine. For the much broader general situation, such approaches either won't work or will likely be a lot less readable. Consider a case where you have to support logic including OR's or NOT's like:
((A && B) || (B && NOT(C)) || (D && (E || F)) )
You'd either string together a raw, literal implementation along the lines of the one Bob_Schor illustrated while recommending against, or you could use the Formula Node I mentioned before to preserve the relative readability of the text-based logic.
Not a critique of earlier replies which definitely addressed the question asked, just offering some additional thoughts since the original problem was a special case that just happened to lend itself to a more-elegant-than-normal pair of solutions.
-Kevin P
11-02-2016 06:59 PM
Kevin, the logic operators are handled by multiple value cases or case ranges. The text solution is a bit more scaleable but,less readable. Join numbers is limited to 64bits. OTOH, if you have a 2^63-1 if else selections, you have much bigger problems😙
11-03-2016 12:28 AM
To-MAY-to, To-MAH-to. I'm just saying that to *me*, the text form of expressing those logical combinations seems much more straightforward and understandable at a glance than schemes that map those logical operations into ranges of magic numbers or involve deeply nested case structures or require a cascading series of various logic operators. It's not that LabVIEW's *incapable*, just that I find it kinda awkward in some areas. It all compiles just fine, but I think the LabVIEW syntax for moderately complex logic or math expressions is often inferior to text code. Not that I'm gonna convert back.
-Kevin P
P.S. Congrats to Cubs and fans, that's why I'm still up now
P.P.S. For the record, I was actually rooting for Cleveland, but there's noone in the NL I'd rather they lose to
11-03-2016 05:49 PM
Just for completeness, here are a couple more ways to do this:
1. Nested Case Structures (as Lynn suggested above)
2. Obfuscated code
Who needs to know the mapping as long as you get the right answer 🙂
11-03-2016 06:34 PM
You may want to look at this idea.
11-03-2016 06:55 PM
One more: Array lookup
11-04-2016 07:17 AM
@GregSands wrote:One more: Array lookup
Beautiful one!