LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of a float to IEEE 754 hexa (and vice versa)

Hello everyone,

 

I need to convert a float into an hexadecimal value to transmit it on a communication bus (I also have to decode the hexa into a float). I need this hexadecimal to respect the IEEE 754 technical standart. I'm trying to do it with the basic functions of Labview but I'm facing some problems. You'll find attached my VI.

 

If someone has already done such a function or know an easier way to do it, I'll be very grateful.

0 Kudos
Message 1 of 13
(7,670 Views)

Let me Google that for you:

 

LabVIEW IEEE 754 float to hex

 

 

Message 2 of 13
(7,665 Views)

I reproduced the exemple of your link and I haven't the same result. Have you tried it yourself?

Then when I look in the Labview help about the function [Mantissa & Exponent], I see the function returns the mantissa and the exponent corresponding to this formula :

value = [Sign] x [Mantissa] x 2^[Exponent]

 

But when you check in the standard, you see the the real formula is:

value = [sign] x 1,[mantissa] x 2^[Exponent - shift]

 

So one of the inner question is how to go from the Labview's mantissa to Standard mantissa?

 

0 Kudos
Message 3 of 13
(7,654 Views)

What's wrong with just using the Type Cast?


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 4 of 13
(7,647 Views)
0 Kudos
Message 5 of 13
(7,642 Views)

That online converter is using a Single.  The default type in LabVIEW for a float is a Double.  Change your representation and it works just fine.


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 13
(7,639 Views)

Ok I've found:

Using only a single as you suggest Crossruls works

But all my previous VI use Doubles, so I cast my Double in Single and then it didn't work any more. So I have to change all my Double into Single.

 

Thank you!!

0 Kudos
Message 7 of 13
(7,631 Views)

Or you can use the Double conversion from the same site you gave me earlier:

http://www.binaryconvert.com/result_double.html?decimal=045049049056046054050053


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 8 of 13
(7,627 Views)

Yes that's how I understood my problem : by checking the double conversion on this website.

But I have to use the singles, because the communication bus I interface with works like that.

0 Kudos
Message 9 of 13
(7,624 Views)

If your communication bus in only using singles, then avoid doubles in your code.

 

How are you converting to a Single from the Doubles?  In my quick experiment, I got the right answer.


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 13
(7,617 Views)