10-01-2020 05:26 AM - edited 10-01-2020 05:27 AM
Can someone please tell me how to convert int16 to float 32 (MSW-LSW)?
Kind regards,
Balázs
Solved! Go to Solution.
10-01-2020 05:50 AM
Not sure exactly what you are after here. Did the To SGL not do what you want? If not, do you have an example to help us understand your issue?
10-01-2020 06:32 AM
I use the following tool for scanning modbus TCP as reference. I would like to find out how to get 61.06516 which is a float32 (MSW-LSW)
Here is my code:
My "Output" is 17096. I reckon this number is the one that should be somehow transformed to 61.06516. Am i right or wrong?
10-01-2020 06:53 AM - edited 10-01-2020 06:54 AM
And this is why examples are so important.
Your problem is you need to use 2 words to combine to make your 32-bit value. Use Array Subset to get words 5 and 6 (index 4 and 5). Then you can just use Type Cast to convert to a SGL value.
10-02-2020 01:15 AM
Hi,
I get 1,39232E+12 as output when MSB=17012, LSB=17096.
Is there something that i am doing wrong?
10-02-2020 01:36 AM - edited 10-02-2020 01:42 AM
You want SGL, not DBL (DBL is eight bytes) change the representation of all your orange elements to SGL. (indicator, diagram constant wired to the top of typecast, NAN in the other case)
You cannot turn four bytes into eight.
Where did you find this VI?
10-02-2020 02:44 AM
I created a numeric indicator then changed its data type to SGL, and the data type of "Casted Number" to SGL (right click -> properties -> data type..)
I found that vi here:
https://forums.ni.com/t5/Example-Code/Cast-Two-I16-Numbers-into-One-Double-Precision-Number-Using/ta...
Thanks for your help!
Regards,
Balázs
10-02-2020 08:04 AM
Here is a pro tip that was not done in the link you provided, nor on CrossRulz's example above.
Make the label visible on that typecast constant and edit it to say SGL. That documents that the intention is to typecast the input to a Single, and not one of the other 5 data types that are also floating points with an orange color.
10-03-2020 05:13 PM
@RavensFan wrote:
Here is a pro tip that was not done in the link you provided, nor on CrossRulz's example above.
Make the label visible on that typecast constant and edit it to say SGL. That documents that the intention is to typecast the input to a Single, and not one of the other 5 data types that are also floating points with an orange color.
That is exactly what I do for constants where it is important to know the data type.