LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert hex (or byte??) to double

Solved!
Go to solution

Hi,

I am terribly sorry but still no lack with that.

I guess you mean to make a formula node?

what kind of input do i provide?

the value i.e. C5D1 is a string as i get it from the instrument.

how do i convert it to a value that i can do calculations with?

 

i tried "Hexadecimal string to number" and then "Mantissa & Exponent" but i get wrong values.

please help!!

0 Kudos
Message 11 of 22
(2,194 Views)

Hi 21232,

 

I would convert the string you get into an array of U8. Then pick the needed bytes and do the calculation with them.

 

I never told to use "Mantissa&Exponent". I gave you formulas to calculate them! You can do the calculation using formula nodes or (my preference) using standard math functions. Try to solve this right now or wait another 2 hours - then I get access to a computer with LabView...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 12 of 22
(2,190 Views)
http://en.wikipedia.org/wiki/Single_precision_floating-point_format

Compare that to your 2-bytes and you'll see quite some similarities. The 1st byte is identical between the two and the 2nd byte should be converted to U16, multiplied with 2 (or bit shifted left 1) and insert an empty byte in #2. That should give 4 bytes that can be type converted to a Single Float. (If you really want it in doubles you can do the a type convert again or modify the routine to 8 bytes)

/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 22
(2,184 Views)

ok i converted the string to an unsigned byte array but i am in a dead end still .The array reads 99 53 100 49 .

i will wait for your sollution GerdW.

thanks a lot.

best regards

thodoros

0 Kudos
Message 14 of 22
(2,179 Views)

Example of 2 byte conversion.  Disclaimer this was a quick example, there may be better logic out there.

 

hex to dec.png

 

Dan

Herrlin

Just trying to spread the LabVIEW love.
0 Kudos
Message 15 of 22
(2,178 Views)

hi herrlin,

thanks for the solution but one quick question,

how do i convert a hexadecimal string to an input for your code

C5D1 is a string that i did not manage to convert to input for your code.

also where is the function for the exponential of 2?i couldn't manage to find it but i did it in a formula node.

cheers

thodoros

0 Kudos
Message 16 of 22
(2,163 Views)

Power of 2 was under Mathematics\Elementary & Special Functions\Exponential Functions directory. Also, once again this is a quick example.

 

hex to dec.png

Herrlin

Just trying to spread the LabVIEW love.
Message 17 of 22
(2,159 Views)

thanks it works perfectly!

and for a 4 byte number?

i.e. CAEF5DCE what changes should i do?

cheers

thodoros

0 Kudos
Message 18 of 22
(2,145 Views)

Hi 21232,

 

as you now have the code for 2 byte FPL and the description how to calc 4 byte FPL don't you want to learn LabView and change the given code to fit your needs on your own???

 

Come on, give it a try!

 

Hint: finding functions is easy using quickdrop <Ctrl>-<Space>

Message Edited by GerdW on 03-09-2010 05:55 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 19 of 22
(2,137 Views)

ok i will

thanks

i am still trying to figure out what the first code does though.

i have zero experience in hexadecimal data manipulation.

i will give it a go but i hope if i don't manage you could give me a push.

thanks again

thodoros

0 Kudos
Message 20 of 22
(2,132 Views)