LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/10/2009) - Type Cast


David_L wrote:

Altenbach,

 

I like the obfuscated code links from years ago, pretty interesting stuff.  However I am COMPLETELY stumped on how the boolean one works.  Want to spill the secret?


When I first saw that example I had immediately thought back to how Booleans used to be stored in memory, versus how they changed to be bytes (was it LV 4 or 5?). Then I thought that it couldn't possibly be due to that. But sure enough when I wrote up a little test VI to duplicate the example, that's exactly what it was. "Sneaky" was the first word that came to mind.

 

After having figured it out I wasn't sure whether to feel proud or sad that I was such a geek. Smiley Very Happy

Message 11 of 13
(806 Views)

One interesting usage of the Type Cast is to name wires.

 

Look at the names on the event structure.

 

 

Rename wires.png

 

Felix

Message 12 of 13
(794 Views)

I like to use typecast to convert numerics to enums and enums to other enums. This only really works if the numerics and enums are the same length, and, preferably, the same data type.  Convert them beforehand if not.

 

I started using this method when I inherited a piece of code with three incompatible enums for the same thing.

 

When using typecast, it is safest if the source and target are the same length.  You can sometimes get away with going from smaller bit size to bigger bit size (e.g. U8 to U16), but I have been burned too many times by this kind of thing, so avoid it.

 

I used to use typecast to send 64-bit integers to 64-bit DLLs before LabVIEW supported 64-bit integers by converting a cluster of two 32-bit integers to a double and telling the call library node it was a double.  There are endian issues with this scheme, but it worked well at the time (this is written up at the end of the Managing Large Data Sets in LabVIEW tutorial).

Message 13 of 13
(763 Views)