LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert hex to float

I have to convert a bit Hex string into a float. I built a vi from the following C code, but it only works on positive numbers. Any suggestions?
 
sample16 = (short) ((MSB << 😎 | LSB);
sample = (float)sample16/32768.0;
sample*=10.0;
 
0 Kudos
Message 1 of 17
(12,539 Views)
You have a ready function in LabVIEW to do that.
 
Look at attached pic to find it
 
 
0 Kudos
Message 2 of 17
(12,517 Views)
Bytes are not "negative" or "positive". Do you have some more information on your conversion? Where is the sign bit?
 
I also assume that your MSB and LSB are originally U8. If it is just a 2byte string, feed it directly into the typecast function.
 
Maybe something along the lines of the attached modification will do the trick. If not, provide some sample inputs and the expected result.
Message 3 of 17
(12,511 Views)
Your vi works. Thank you
0 Kudos
Message 4 of 17
(12,472 Views)

Dear

I am trying to convert 4 bit Hex string to floating number. Dut it does not work. 

Please help.

Thanks

0 Kudos
Message 5 of 17
(9,491 Views)

Do you have a set definition of how the float is constructed?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 17
(9,475 Views)

Thanks Crossrulz

How to set definitions?

Thanks

Hong

0 Kudos
Message 7 of 17
(9,449 Views)

Hong.Zhang@agresearch.co.nz wrote:

How to set definitions?


He is asking you for documentation of the format.

 

You strings don't conform to the IEEE 754 definition of SGL (big or little endian).

 

What device is generating the hex string? Do you have a manual?

 

0 Kudos
Message 8 of 17
(9,444 Views)

Hi 

0 Kudos
Message 9 of 17
(9,419 Views)

Hong.Zhang@agresearch.co. wrote:

Hi @altenbach


You are not giving us any useful information.  Look up the manual of your device.  Somewhere in there should be a definition of how the numbers are built up.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 17
(9,401 Views)