LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number array to boolean array

Solved!
Go to solution

I have a 1D array of 16 bit integers (they are all 0 or 1's).  I would like to convert it to boolean array but when I try to use num to array function a broken wire appears:

 

RFeng_0-1589394072723.png

 

0 Kudos
Message 1 of 8
(3,882 Views)
Solution
Accepted by RFeng

Hi RFeng, I think that function you are attempting to use is for converting 1 numeric (not an array) to its binary representation. You can just use the "not equal to zero" function to convert your numbers into booleans.

Message 2 of 8
(3,877 Views)

It looks like you are using the Number to Boolean Array primitive.  This converts a *single* number to an array of Booleans.  One way of converting an array of integers to an array of Booleans is to just pass it to the Greater Than 0? primitive.  Any value in the input array that is greater than zero then results in a TRUE value in the output array.

Message 3 of 8
(3,862 Views)

@PsyenceFact wrote:

It looks like you are using the Number to Boolean Array primitive.  This converts a *single* number to an array of Booleans.  One way of converting an array of integers to an array of Booleans is to just pass it to the Greater Than 0? primitive.  Any value in the input array that is greater than zero then results in a TRUE value in the output array.


I use "greater than zero" just because my mind accepts "greater than zero" a little more readily than "not equal to zero".  I guess that's because it's a tiny bit less ambiguous.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 8
(3,839 Views)

I still (partially) recall some language or environment I used way back in the 90's (maybe even the 80's ?) where booleans were typically signed ints with a -1 value (all bits set high).  As I recall, any non-zero integer value would evaluate as True, positive or negative alike.  A "greater than 0" comparison would have wrongly missed all the built-in boolean constants.

 

So my habit would be to check "not equal to 0" so I don't have to check to see whether the int is signed or unsigned.  (I'm pretty sure this came up in another thread not all that long ago, but I couldn't find it easily just now.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 5 of 8
(3,818 Views)

@Kevin_Price wrote:

I still (partially) recall some language or environment I used way back in the 90's (maybe even the 80's ?) where booleans were typically signed ints with a -1 value (all bits set high).  As I recall, any non-zero integer value would evaluate as True, positive or negative alike.  A "greater than 0" comparison would have wrongly missed all the built-in boolean constants.

 

So my habit would be to check "not equal to 0" so I don't have to check to see whether the int is signed or unsigned.  (I'm pretty sure this came up in another thread not all that long ago, but I couldn't find it easily just now.)

 

 

-Kevin P


That was something I never knew!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 8
(3,795 Views)

@Kevin_Price wrote:

So my habit would be to check "not equal to 0" ...

 


Exactly. This is the only correct interpretation of the definition:

 

Quote from here:

 

"LabVIEW stores Boolean data as 8-bit values. If the value is zero, the Boolean value is FALSE. Any nonzero value represents TRUE."

0 Kudos
Message 7 of 8
(3,788 Views)

@Kevin_Price wrote:

As I recall, any non-zero integer value would evaluate as True, positive or negative alike.  A "greater than 0" comparison would have wrongly missed all the built-in boolean constants.


I know that is the case in C/C++.  LabVIEW follows the same suite.  I can't say about any other language.  So, yes, "Not Equal To Zero" is the proper operation.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(3,780 Views)