LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

float string to decimal

Solved!
Go to solution

Hello,

 

I am in internship and I have a problem with my system.

 

I send information between a PCB to my computer. I send in my frame, a float in string format and I would like to make the conversion in LabView to show the good value.

 

For example, there are something like that in my buffer : 3E94C2DC and I would like to convert that in decimal format.

 

Could you help me please.

 

Thanks in advanced.

 

Quentin

0 Kudos
Message 1 of 12
(5,566 Views)
Solution
Accepted by topic author Mobile

Not clear to me:

Source:  '3E94C2DC' in what format? 2 words in Hex , or 8 bytes from serial coded in ASCII?

Output format:   single float?(0,290549)

conversion01.png

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 2 of 12
(5,545 Views)

It is 8 bytes from serial coded in ASCII. And I would like to convert this 8 bytes of my float string to decimal number. Then I could show the real value in LabView.

 

My output that I would like to have is around 0.30

0 Kudos
Message 3 of 12
(5,539 Views)

Hi Quentine

 

Maybe you can use Hexadecimal String To Number Function (http://zone.ni.com/reference/en-XX/help/371361G-01/glang/hex_string_to_number). I attached an example.

 

Regards

 

Greg

0 Kudos
Message 4 of 12
(5,533 Views)

Did you see the number in my question ??

What LV version do you have ?

Just save and paste the snippet from my previous post 🙂

However, here as a vi in LV2009

 

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 5 of 12
(5,527 Views)

Sorry Henrik,

 

When I started creating post, there was no answer yet. After I send my post I saw your post. Maybe next time I will be faster 😉

 

regards

 

Greg

0 Kudos
Message 6 of 12
(5,518 Views)

I am sure it is not clear taht I have.

 

I have a float number, I send the float number in my buffer with C code with printf instruction like that :

 

printf ("%x", numberthatIhave);

 

In labview I read my buffer, so it is a string format. And I would like to convert the message (hex value in string format) to a decimal number to show the number.

 

But I do not know how I can do that...

0 Kudos
Message 7 of 12
(5,516 Views)

The snippet /vi should solve your problem.

The string is converted to a binary 32bit respensentation and then converted to a single float (also 32bit) 

To check the result it would have been usefull to post an exact input / output pair 😉 

 

Have fun 🙂

 

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 8 of 12
(5,506 Views)

test.JPGWhen I make the test with you solution, I have 1.049. Whereas I would like to have 0.30

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

Do you see the minor but important difference ?

I used the typecast to convert U32 to SGL 😉

And you get 0,290549

conversionFP.png

(U32 displayed in Hex)

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 10 of 12
(5,483 Views)