LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert (0,1) values to Boolean

Solved!
Go to solution

Hello,

 

The conversion Boolean to (0,1) does exist.

What about inverse conversion, i.e. (0,1) to Boolean.

Actually I'm trying to convert Sign function output (-1, 0, 1) to Boolean.

With ABS function I can reduce (-1, 0, 1) to (0, 1), but then ... how to proceed ?

 

Thanks

 

0 Kudos
Message 1 of 12
(25,306 Views)

Ok, the solution is quite simple - equal comparator.

Sorry for this post

0 Kudos
Message 2 of 12
(25,300 Views)
Be careful if using equality floating point numbers - what might appear to be 1, might not actually be 1 depending on how the number is represented in floating point (e.g. it might be 1.00000000000000000000001) and so an Equals? would be false.

Just something to bear in mind - if you're using integers then this isn't a problem.

LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 3 of 12
(25,291 Views)

Thanks Sam,

 

Sign function has 15-bit precision, I think for my case it will be sufficient.

At other side the problem revealed  a little bit more complicated, i.e. (-1, 0, 1) to boolean - using ABS just converts -1 to 1, wheras I want -1 and 0 --> FALSE, 1 --> TRUE

 

0 Kudos
Message 4 of 12
(25,286 Views)

Here is a solution

convert sign output to boolean.JPG

0 Kudos
Message 5 of 12
(25,281 Views)

Just use something like this:

Convert Number to Boolean.png

 

As for your 'other side the problem' - just use a simple select/case structure to get the appropriate value out. Post your code because it sounds like you're over-complicating things.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 6 of 12
(25,277 Views)

Thanks Sam,

 

It seems that I've found a solution (post above).

Quite simple, isn't it ?

 

0 Kudos
Message 7 of 12
(25,272 Views)

@Pavel_47 wrote:

What about inverse conversion, i.e. (0,1) to Boolean.


The exact inverse is Not Equal To Zero.  It will take even give a TRUE value for your -1 case as well.


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 12
(25,258 Views)

For my case the truth table is as follows:

-1, 0 => FALSE

1 => TRUE

 

I think the solution using increment (as it's shown above) isn't so bad.

 

0 Kudos
Message 9 of 12
(25,238 Views)
Solution
Accepted by topic author Pavel_47

Hi Pavel,

 

in this case a ">0" comparison is simpler/"better" than your "+1" "solution"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 12
(25,232 Views)