LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

type cast explanantion

Solved!
Go to solution

Hi, all. I am in need of help to understand the operation of type cast and what is the technical meaning of the words 'flattening' and 'unflattening' that is used in 'type cast' explanation. Thanks in advance!

Type cast.JPG

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
0 Kudos
Message 1 of 14
(3,732 Views)
Solution
Accepted by dhans

In the variant function panel you have Flatten and Unflatten functions (try 'em out). What they do is basically interpret any data as a string (flatten) and try to interpret a string as a specific data type (unflatten). In C and derivates it'd be (void*) data, i.e. interpret any data as pure general data and not type specific data.

Does that help?

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 14
(3,677 Views)

Hi dhans,

 

casting means to change a datatype without changing the underlying data!

 

Example:

You have a SGL with a value of "-4". This value is stored in memory using the bytes "C0 80 00 00".

When you typecast this SGL value to an U32 you get the decimal value "3229614080", which is still the same bytes "C0 80 00 00" in memory…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 14
(3,672 Views)

@GerdW wrote:

Hi dhans,

 

casting means to change a datatype without changing the underlying data!

 

Example:

You have a SGL with a value of "-4". This value is stored in memory using the bytes "C0 80 00 00".

When you typecast this SGL value to an U32 you get the decimal value "3229614080", which is still the same bytes "C0 80 00 00" in memory…


Hi GerdW,

  I am lit bit confused. In your statement, only the hex value " C0 80 00 00 " which is an address of memory will be converted to U32 as 3229614080. Then how can I get that modified " -4 " as an output from type cast vi instead of address. 

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
0 Kudos
Message 4 of 14
(3,654 Views)

Hi dhans,

 

only the hex value " C0 80 00 00 " which is an address of memory

Why do you think of "addresses" here? I talk about values/data!

These 4 bytes can represent

- an array of 4 I8/U8 values

- an array of 2 I16/U16 values

- a I32/U32/SGL value

- a string of 4 chars

- many other options

 

But still in memory you always have those 4 bytes!

Typecasting means to reinterprete the bytes in memory using different datatypes…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 14
(3,648 Views)

Hi GerdW,

   I got your point. What you have said is that 4 bytes can be of any data type that can be cast but the data " -4 " will be " -4 " only. No change in that data. Am I right?

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
0 Kudos
Message 6 of 14
(3,645 Views)
Solution
Accepted by dhans

Hi dhans,

 

but the data " -4 " will be " -4 " only. No change in that data. Am I right?

Not really!

The underlying bytes in memory will not change, but the interpretation of these bytes may/will differ!

Interpreting the bytes mentioned before as SGL will result in -4, but when typecasting the very same bytes to U32 you get "3229614080"!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 14
(3,615 Views)

Hi GerdW, 

Thanks alot. I understand. Labview stores SGL " -4 " as "C0 80 00 00" and this will be interpreted in different types of data. Thanks a lot man!

Best Regards,
Dhans 😉
Kudos are welcome 😉
Aspirant Labview Programmer (Labview 14) 😉
0 Kudos
Message 8 of 14
(3,607 Views)

A good analogy is languages. The same letters can mean different things depending on language, but the data is the same. Type casting is basically saying 'interpret this text in language X' instead.

 

'well' has atleast 3 interpretations in english alone, so type casting is like saying 'it's not the object, but the adjective'

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 14
(3,561 Views)

@Yamaeda wrote:

A good analogy is languages. The same letters can mean different things depending on language, but the data is the same. Type casting is basically saying 'interpret this text in language X' instead.

 

'well' has atleast 3 interpretations in english alone, so type casting is like saying 'it's not the object, but the adjective'

/Y


 

Forums broke my emoticons! Trying out a new one...

 

 

Spoiler

 

I followed you right up the the end when my brain slipped gear thinking "Adective Oriented Programming".

 

I need a vacation. I think I will just take the rest of the year off

Spoiler
(which I have scheduled to sart at 2:00 this afternoon).

 

 

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 14
(3,545 Views)