LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

negation 0 to 1

Solved!
Go to solution

Hi,

 

is there any function in labview that negates the input signal (0 to 1)? Thanks for help.

0 Kudos
Message 1 of 18
(2,069 Views)
Solution
Accepted by Tim970

There is a function that negates an input, called Negate, it can be found among Numeric functions, but you'd get a result of -1 if you input 1.

 

What you are describing is more of a boolean negation, in which case you have a Not function among Boolean functions. If you insist on using numbers for this then transform to boolean, negate and then transform back.

 

I don't think there is a single function that does this for numbers tho.

 

EDIT:

3 ways to do it

AeroSoul_0-1705480620355.png

They all output the same, if you only use 0 and 1.

0 Kudos
Message 2 of 18
(2,060 Views)
Solution
Accepted by Tim970

Hi Tim,

 

You may want to convert your signal to boolean first by using one of the comparison functions (e.g. "Equal To 0?", which implicitly negates the value), then use "Boolean to (0, 1)" to convert it back to Integer:

raphschru_0-1705481166131.png

 

What is the input and output signal data type ? Integer ? Boolean ?

 

Regards,

Raphaël.

Message 3 of 18
(2,056 Views)

Thanks, now it works. 

 

Best regards,

 

Tim

0 Kudos
Message 4 of 18
(2,053 Views)

What about this:

y := 1 - x
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 18
(1,974 Views)

@GerdW wrote:

What about this:

y := 1 - x

I was thinking to add 1 and then AND with 1.  But yours is simpler still.

x = (x+1) && 1

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 6 of 18
(1,962 Views)

With an integer type, you could also just XOR with 1.  That'll transform 0-->1 and 1-->0.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
Message 7 of 18
(1,954 Views)

@crossrulz wrote:

@GerdW wrote:

What about this:

y := 1 - x

I was thinking to add 1 and then AND with 1.  But yours is simpler still.

x = (x+1) && 1

There might be a programming language where && is a binary AND but generally in the languages I know you would need to use & here since && is a logical AND.

 

For x = 1, our expression evaluates to:

 

x = 2 && 1

 

and in C (and C++, C#, Java and likely several others) this would still be true (1) since any value other than 0 is normally treated as true (1) when evaluating values as logical value.

 

Even Pascal/Modula (because of the original := assignment operator in the post you responded to) uses the single & and | as binary operator, but "and" and "or" as logical operator.

 

The LabVIEW Boolean operator nodes perform automatically a binary operation on integers and only a logical operation on Booleans. This is because in LabVIEW the Boolean data type is a first class element. In C and most C influenced languages Boolean was originally NOT an existing data type and instead an integer was used to emulate Booleans. Only later dialects of C introduced an explicit Boolean datatype but backwards compatibility required it to still work like earlier versions.

Rolf Kalbermatter
My Blog
Message 8 of 18
(1,932 Views)

@rolfk wrote:

There might be a programming language where && is a binary AND but generally in the languages I know you would need to use & here since && is a logical AND.


Yep, you caught me.  I need to get back into playing with my Pi Pico to dust off many layers of C rust.


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
Message 9 of 18
(1,897 Views)

@Tim970 wrote:

is there any function in labview that negates the input signal (0 to 1)? Thanks for help.


Obviously we need to know the datatype (integer? DBL? scalar? array? etc.). Where does the signal come from? (if it is from a digital input, it might already be boolean and if it is from an analog input, it might be close, bun not exactly zero or one)

 

Can you guarantee that the input is never outside the range 0..1? If not, what should happen if the input is invalid?

 

If it can never be outside 0..1, maybe a boolean datatype would be a better choice to carry along?

0 Kudos
Message 10 of 18
(1,866 Views)