Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Type Cast Function

LabVIEW 2013 Help

Edition Date: June 2013

Part Number: 371361K-01

»View Product Info

Owning Palette: Data Manipulation Functions

Requires: Base Development System

Casts x to the data type, type, by flattening it and unflattening it using the new data type. If the function must reinterpret data instead of transforming it, LabVIEW uses a temporary buffer.

The connector pane displays the default data types for this polymorphic function.

Details  

type is the data type to which you want to convert the data. Wire any constant or control to type to set the data type to which you want to convert the data. LabVIEW ignores any data in the constant or control you wire to type.
x is the data you want to convert to type. x can be any data type.
*(type *) &x is the value provided in x and converted to the same data type as type.

Type Cast Details

Effects of Mismatching the Sizes of X and Type

This function can generate unexpected data if x and type are not the same size. If x requires more bits of storage than type, this function uses the upper bytes of x and discards the remaining lower bytes. If x is of a smaller data type than type, this function moves the data in x to the upper bytes of type and fills the remaining bytes with zeros. For example, an 8-bit unsigned integer with value 1 type cast to a 16-bit unsigned integer results in a value of 256.

Type Casting Arrays

You can use this function with an array of scalars or an array of clusters of scalars. For example, if you typecast an array of four 16-bit integers to an array of 32-bit integers, the output array contains two elements, each formed from the bits of pairs of elements from the input array. If the input array does not contain enough bytes to form a whole number of output elements, LabVIEW omits the final elements of the input array.

Type Casting References

If you want to upcast or downcast references, use the To More Generic Class function and the To More Specific Class function instead of the Type Cast function. The Type Cast function does not provide error checking, but the To More Generic Class function and the To More Specific Class function do. The To More Specific Class function has error in and error out parameters. The To More Generic Class function breaks the wire at edit time when you wire a reference to an incompatible target class.

Type Casting Boolean Data from Early Versions of LabVIEW

If x might contain Boolean data created with LabVIEW 4.x or earlier, right-click this function and select Convert 4.x Data from the shortcut menu to convert the data to a format that is readable by LabVIEW 5.0 and later. In Convert 4.x Data mode, this function interprets x as if the data is stored in LabVIEW 4.x data storage layout and displays the icon for this function with a red 4.x on it. LabVIEW 4.x and earlier stores Boolean data in two bytes unless the data is in an array, in which case LabVIEW stores each Boolean element in a single bit. LabVIEW 5.0 and later stores Boolean values in a single byte, regardless of whether it is in an array. National Instruments recommends reworking any application that uses the Convert 4.x Data mode as a long term solution.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit