LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert signed int to float

hello,

I am a bit new to labview and I need some help with converting a signed integer to float, for example my integer is "-34359738" then i need to multiply it with 2^-36 and i am spouse to receive "-4.99999e-4", however when i convert the signed int to SGP i receive the number "-40.494e36"

 

 

thank you for your assistance

0 Kudos
Message 1 of 4
(3,307 Views)

Hi Dan,

 

you really need to describe the whole algorithm on how to convert that I32 value into SGL data!

 

Your "-34359738" is the same as the hex value 0xFDF3B646.

The SGL value -4.99999e-4 is represented by a hex value of 0xBA03125D.

These are very different values - and you need to explain the conversion between them!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(3,279 Views)

Typecasting isn't your best choice here.  As others have mentioned, the bits you're working with don't have the same meaning.  If you'd like to understand why, you can google plenty of resources on floating point to understand how that value is composed.

 

Instead, save yourself the frustration.  Hit "ctrl+space"  Type in "to single" and watch it populate.  Drop the to single precision floating point.  Wire your value in and out.  Call it a day.

0 Kudos
Message 3 of 4
(3,263 Views)

I'm not certain I understand the point of this exercise, except maybe to teach you something about numeric representation (Floats vs Integers) and number sizes.

 

Let's assume this is the point of this exercise.  What do you notice about the multiplier?  It is 2^-36.  Is there anything "special" about this number?  Do you see any significance in the "2"?  Can you think of a way to get rid of the negative exponent?  Is there anything (relative to LabVIEW Integer representations) significant about "36"?

 

You can find the answer to this problem by taking the first number, a "slight modification" of the second number (hints in the paragraph above", and doing a single arithmetic operation on them that will give you a Dbl (that's another hint on what operation you use -- which one turns two integers into a Dbl?).

 

When I first did this, the answer I got was -0.0005.  I needed to do some manipulation of the Properties of the Indicator to get the answer in the form -4.999999946E-4 (I used a few more decimal points).

 

Give it a try.  It's all simple Math on the Numeric Palette -- no need for anything fancy on its sub-Palettes.

 

Bob Schor

0 Kudos
Message 4 of 4
(3,258 Views)