LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change Hex String to Decimal number?

I am reading a HEX string value represented as (4066 C147 AE14 7AE1) that represents a double value of (182.04). How do I convert this string to the decimal number that I can use? I can use the type cast function to convert the decimal to a string but I cannot figure out how to do the reverse, which is what I really need. Any help would be great!
0 Kudos
Message 1 of 11
(5,287 Views)
Try this example: <>
Message 2 of 11
(5,287 Views)
I have tried this vi and it does not work for decimal valued numbers. I have tried modifying it and still had no luck.
0 Kudos
Message 3 of 11
(5,287 Views)
sdrochek,
I see that now, and it would need a little fine-tuning to fit your need; however, with Brian's answer working, looks like you should be OK.
Let him know how it went and thanks for the reply anyway, Doug.
0 Kudos
Message 5 of 11
(5,287 Views)
The cast function can be used to convert the string back to a number the same way that you went from a number to string. You just have to make sure that you wire a dbl constant to the type terminal of the Type Cast function. I just tried it with the values that you posted and it worked.

Brian
Message 4 of 11
(5,287 Views)
Brian, Thanks this works great. I did not know the features behind this function. It doesn't have a lot of documentation on it and I've only had LV basic I and II.
0 Kudos
Message 7 of 11
(5,287 Views)
> I am reading a HEX string value represented as (4066 C147 AE14 7AE1)
> that represents a double value of (182.04). How do I convert this
> string to the decimal number that I can use? I can use the type cast
> function to convert the decimal to a string but I cannot figure out
> how to do the reverse, which is what I really need. Any help would be
> great!

There are a couple steps involved here. First scan the string and
produce an array of U16 numerics. I did this with a For loop and
the Hex String to Number node. Collect the four numeric outputs
and verify that they are correct, probably by changing the formatting
to Hex. The next step is to wire the array of four U16 values to a
Type Cast node and convert it to a DBL. The type cast is the square
peg
/round hole node in the Advanced/Data Manipulation palette.

Greg McKaskle
0 Kudos
Message 6 of 11
(5,288 Views)
I've tried this method using LabVIEW 7.1, and the typecast function doesn't work.

I have a 128 byte long string received via UDP from a custom instrument.  The only way I seem to get convert is to select the subset of bytes from my string, convert them using String to Byte Array, use a For loop and shift register to convert the bytes to a string of HEX characters, then convert to a double using Hexadecimal String ti Number with a Double as a default.

My method works, but I can't help but think that there is an easier way...


0 Kudos
Message 8 of 11
(4,998 Views)
The 128 byte HEX string gets converted to one single decimal number?
 
Post:
  1. a complete hex string,
  2. the number that it represents and 
  3. the code (VI or screen shot) that you are using to do the conversion

and I'm sure someone will be happy to suggest improvements if any exist.

0 Kudos
Message 9 of 11
(4,991 Views)
I tried this again this morning. I can perform the typecast by selecting the 8 bytes that represent my double from the UDP string, typecasting this 8 byte string to an array of U16, then typcasting the U16 array to Double.  See attached VI (version 7.1).
 
I was trying to refactor existing code yesterday.  I can only assume that my problem was related to the state of my environment.  After rebooting and trying again this morning, things are working.  I shut down every night, and created a new VI to run this test. Are there any known LabVIEW bugs regarding typcasting strings that might have been cleared by starting fresh?

Message Edited by Phillip Brooks on 12-02-2005 07:32 AM

Message 10 of 11
(4,974 Views)