LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert string (single precision float) to decimal

Solved!
Go to solution

Hello,

 

I am using the basic serial read and write vi to communicate with a device.  The response I am getting (displayed in hexadecimal form) is 4606 8D3B, which from what I understand (from this discussion: http://forums.ni.com/t5/LabVIEW/string-to-number-conversion-a-very-interesting-observation/m-p/32170... ) the data is not actually hexadecimal but rather binary and is just displayed hexadecimal for the user. 

 

The manual of my device says this piece of information is "Float - 4 byte ANSII standard single precision, low to high" and I am trying to convert this string into a decimal value.  (it should be 0.004 or 4.xx e-3)  So far I have written a program that seperates the bytes into an array of 4 bytes, converts each to binary, then unbundles all the binary bits and am trying to bundle back the binary bits into the exponent and mantissa to calculate the value, but this seems rather convoluted and I am hoping there is a simpler function in that does all of this automatically.  Also, since the response is low to high I understand I need to first flip the number to 3B8D 0646 to make it high to low, but I think I have done that already, it's just the conversion that I am not sure how to do.

 

Any help would be appreciated, thanks

 

Alex

0 Kudos
Message 1 of 5
(4,111 Views)
Solution
Accepted by topic author ac1054

Try this:

 

 

0 Kudos
Message 2 of 5
(4,106 Views)

With that I am getting "Error 74".  (Maybe I just set it up wrong, I am relatively new to labview)

0 Kudos
Message 3 of 5
(4,088 Views)

Your constant is a DBL and the hex string is not what you said was the response - 4606 8D3B.

0 Kudos
Message 4 of 5
(4,084 Views)

Ahh I see, I thought I had to reverse the number first.  Changing the constant to SGL and inputing 4606 8D3B gives me 0.00430373, which is correct.  Thank you!

0 Kudos
Message 5 of 5
(4,080 Views)