LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

negation 0 to 1

Solved!
Go to solution

I love how these simple questions often turn in a race to the bottom, who's gonna provide answer with the least functions/smallest size 😄

0 Kudos
Message 11 of 18
(1,184 Views)
@AeroSoul wrote:

I love how these simple questions often turn in a race to the bottom, who's gonna provide answer with the least functions/smallest size 😄


code golf 🙂 https://www.youtube.com/watch?v=MqZgoNRERY8

 

@rolfk wrote:

@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


a sparse occasion to use labviews expression node ...Gerd's approch is fairly easy to convert to primitives

alexderjuengere_0-1705570165436.png

the bitwise && gave me a little struggle to convert to primitives -

 

but wait, the 'formula node' and 'expression node' is based on C, and it turns out, && must be changed to &, as rolf predicted. nice!

 

Spoiler
0-1-invert.png

 

 

0 Kudos
Message 12 of 18
(1,165 Views)

Because choice is so much fun, here my "limited" selection of options:

 

Invert Boolean Integer.png

Caveat: they only work fine if the input is guaranteed to be in the range (0, 1). Other values will cause different results, some of them more intuitive than others. This is where Christian Altenbach's post comes in: we need to know the conditions and requirements for a proper selection of the various options.

 

And the -x + 1 only works for signed integers. The -x node refuses unsigned integers on its input, a sensible limitation. Interestingly the formula node version of this does not only not have this limitation but effectively still produces the right result. Apparently it promotes the value to a signed int internally and then converts it back to the input data type.

 

And I think I discovered a strange bug in the snippet generation. This is the actual VI block diagram from which the snippet was generated:

rolfk_0-1705572450901.png

Anybody can notice the difference in two of the indicator labels?

Rolf Kalbermatter
My Blog
Message 13 of 18
(1,156 Views)

@rolfk wrote:

 

Anybody can notice the difference in two of the indicator labels?


Isn't it just a simple LabVIEW rule: Don't have two indicators or controls with the same label?

By the way I see four differences.

0 Kudos
Message 14 of 18
(1,136 Views)

@UliB wrote:

@rolfk wrote:

 

Anybody can notice the difference in two of the indicator labels?


Isn't it just a simple LabVIEW rule: Don't have two indicators or controls with the same label?

By the way I see four differences.


It's not something that is normally enforced. Yes, if you create new controls they will be made having unique labels but nothing prevents one from renaming them back. Seems the snippet tool is kind of recreating the diagram in the background through scripting to get the VI code. Possibly because I did not save the VI?

Rolf Kalbermatter
My Blog
Message 15 of 18
(1,128 Views)

@rolfk wrote:
It's not something that is normally enforced.

<Offtopic> Similarly, I occasionally run into issues when just doing a copy/paste of graphs into e.g. MS paint. If a graph is set to autoscale, but the axes have been manually panned or zoomed, the pasted picture is autoscaled to the data again and thus looks different than on the front panel. Tedious! </oftopic>

0 Kudos
Message 16 of 18
(1,096 Views)

Didn't even know you could do that, i normally just print screen stuff like this...

0 Kudos
Message 17 of 18
(1,081 Views)

Yes, LabVIEW is doing something with the code of the snippets. As you can see in my post here, at recipe 06 I overlooked the change of labels 😫, later I  tried to give these labels unique names by a leading underscore, hidden (well, badly) by the terminal, as can be seen at 07 & 08.

A space will be trimmed and the label will then be renamed.

Greets, Dave
0 Kudos
Message 18 of 18
(1,072 Views)