LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with with Array of U8 to Array of Array of Boolean

I am trying to convert the numbers in an array of U8 into 8-bit boolean arrays. The online help of Labview 6i says I can wire an array of numbers to the 'Number to boolean array' VI. Unfortunately I get an error.
If I put it into a for loop with the array as an indexed input it works, but it is quite slow. Any thoughts?
0 Kudos
Message 1 of 11
(5,557 Views)
My online help says that the only valid input for the Number to Boolean Array is a number and not an array. When I run an array through a for loop it doesn't seem to take that long. How big is your input array, what OS are you using, what type of computer?
0 Kudos
Message 2 of 11
(5,557 Views)
In article <50650000000800000035630000-1031838699000@exchange.ni.com>,
"Heiko Fettig" wrote:
> The online help of Labview 6i says I can wire an array of numbers to the
> 'Number to boolean array' VI. Unfortunately I get an error.

Wow, you're right! I looked at the online help and it says the input is
polymorphic. They also verify this by stating you can use arrays and
clusters for input. I ran into this problem once before but I ended up
using a For Loop like you, and I forgot about it. I should have read the
help file. I'd be interested in seeing what the output would be for a
cluster of arrays or an array of clusters... that is if it worked.

Perhaps this is a LV bug? For now you may be stuck with the For Loop.

-Kevin
0 Kudos
Message 3 of 11
(5,557 Views)
Dennis' answer is right on. The best way to do this is using a for loop (just as you tried) and it should be pretty fast.

In addition to stating your OS and processor speed, you may want to describe what you are ultimately trying to accomplish with the data. Perhaps with more info we can suggest an alternative method of processing your data.

Scott
0 Kudos
Message 4 of 11
(5,557 Views)
The best way is to use Type Cast from 1-d Array of U8 to Boolean 1-d Array and to use Reshape Array to 2-d Array.

From my tests i obtained that this method is most quick.

Good luck, Nadav.
0 Kudos
Message 5 of 11
(5,557 Views)
I tried that, but could not make it work. If I wire the U8 array (1D) to the left of the type cast and a boolean array constant (1D) to the top of the array, I get a boolean array output, but only one boolean per U* in the array. If the U8 is 0 the boolean is FALSE, otherwise it is TRUE.
This seems to make some sense since LV stores each boolean as 1 byte.
How did you manage to convert the U8 array to an 8-bit array?
0 Kudos
Message 6 of 11
(5,557 Views)
0 Kudos
Message 7 of 11
(5,557 Views)
The type cast doesn't due any conversions or change the data in any way. It just tells LabVIEW to look at the data in a new way.

As you noted, each boolean is stored as 1 byte, so doing a *normal* typecast will give the results you describe. As you say this makes sense. Zero translates to False, anything else to True.

However, this wasn't always the case. In LabVIEW 4.x and earlier, boolean arrays were stored as packed bits and a type cast of U8 to boolean array would give you an 8 element boolean array.

Nadav's post reminded me of this, so he was right but he didn't give you the full story. If you right click the typecast node, you can select "Convert 4.x Data" and you should get the results you desire.

Thanks Nadav for the
reminder of this "forgotten" capability.

A caveat: It is possible that NI could discontinue this convert option in future versions of LabVIEW. BTW, this option also exists for the flatten/unflatten functions.

The for loop method is still very valid and I don't think you should be experiencing speed problems with that either (unless [maybe] you're working with really huge arrays or limited RAM).

Good Luck,
Scott
0 Kudos
Message 8 of 11
(5,557 Views)
Thanks, that's exactly where my problem was. Now it works.

Interesting side-effect, though: using the type-cast versus the number-to-boolean-array produces reverse order of bits 😉
0 Kudos
Message 9 of 11
(5,557 Views)
I don't understand you.
Please look at example that attached above: booleans are with exactly same order as bits of numbers.
0 Kudos
Message 10 of 11
(5,557 Views)