LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Little Endian Hex String to Single Precision Floating Point

Solved!
Go to solution

I'm done a lot of tinkering and searching, but despite all the very similar examples I've found, I feel I'm limited by my lack of programming knowledge. I am given values like 0000c641 which I have to convert to 41C60000 which should convert to 24.75 as an IEEE754 standard 32-bit single precision float. I've seen very similar examples with boxing and unboxing, but I simply can't figure it out. Thanks.

 

0 Kudos
Message 1 of 11
(8,331 Views)

Boxing and unboxing? Not sure what you're referring to there. We need to be perfectly clear on what the input is. You said it's a "hex string". Well, that's a little vague. Is it a string control/constant that's set to "normal display mode", and you have the character sequence of 0000c641. Note that I am explicitly saying characters there. This is different than having the string set to "hex display mode" and seeing the value 0000c641. Note again that I'm being explicit there. Two VERY different things, requiring two VERY different solutions. 

Message 2 of 11
(8,323 Views)

I'm pulling these from VISA reads from my instrument, but as it stands now, I have the hex strings are string controls in NORMAL MODE. So calling them character sequences as opposed to hex strings would be more accurate I suppose.

0 Kudos
Message 3 of 11
(8,319 Views)

Endianness usually refers to word (int) order, whereas in you example the byte order must be inverterd accross the whole 4 bytes....

I think this is what you want - albeit brute force....

 

 

 

LittleEndian.jpg

Message 4 of 11
(8,314 Views)
Solution
Accepted by topic author Gzimmer

OK, then if you have actual letters coming in, there's a couple of ways you can do this. You can basically rearrange the string to get it in the order that LabVIEW expects. Or, you can do the same thing by using the data manipulation functions:

 

Download All
Message 5 of 11
(8,307 Views)

@S1ack wrote:

Endianness usually refers to word (int) order, whereas in you example the byte order must be inverterd accross the whole 4 bytes....

I think this is what you want - albeit brute force....


That method won't work, since the user indicated they have a string coming in, not a number.

 

Besides, there's a far simpler way. See method 2 from my response. Just connect the numeric control directly to the Flatten to String function. Smiley Wink

Message 6 of 11
(8,301 Views)

smercurio_fc wrote: 

Besides, there's a far simpler way. See method 2 from my response. Just connect the numeric control directly to the Flatten to String function. Smiley Wink


Unflatten from String looks like the way to go here, but just wanted to throw in one more option.  It's a lot easier to reverse the bytes after converting to a number, rather than rearranging the letters in the string:

reverse bytes and convert to SGL.png

Message 7 of 11
(8,295 Views)

With hex characters in a string in normal mode.

 

Message 8 of 11
(8,292 Views)

@smercurio_fc wrote:
That method won't work, since the user indicated they have a string coming in, not a number.

 


Indeed, that information appeared whilst composing the reply.

 

Message 9 of 11
(8,288 Views)

Ah, so many options, so few cats in this world to skin...

Message 10 of 11
(8,283 Views)