ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

取消
显示结果 
搜索替代 
您的意思是: 

float string to decimal

已解决!
转到解答

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 项奖励
1 条消息(共 12 条)
5,754 次查看
解答
接受人 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 ǝɥʇ'


2 条消息(共 12 条)
5,733 次查看

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 项奖励
3 条消息(共 12 条)
5,727 次查看

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 项奖励
4 条消息(共 12 条)
5,721 次查看

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 项奖励
5 条消息(共 12 条)
5,715 次查看

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 项奖励
6 条消息(共 12 条)
5,706 次查看

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 项奖励
7 条消息(共 12 条)
5,704 次查看

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 项奖励
8 条消息(共 12 条)
5,694 次查看

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

0 项奖励
9 条消息(共 12 条)
5,679 次查看

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 项奖励
10 条消息(共 12 条)
5,671 次查看