Our online shopping is experiencing intermittent service disruptions.

Support teams are actively working on the resolution.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert signed 32-bit hex string to ascii string

I am looking for a way to convert a signed 32-bit hex string to decimal string. From what I've seen so far, negative hex numbers are not support, but there must be a way to manipulate a signed 32-bit hex string into a decimal string. Any body have any ideas?
0 Kudos
Message 1 of 18
(9,884 Views)
Questions like this are difficult to answer because everyone seems to use the terminology of ASCII and hex string in different ways.  Please post an example of your "32 bit hex string"  data and what it should convert to.  Is this string 4 bytes?  I'm not sure what you mean by "negative hex numbers are not support[ed]".  A 4-byte number can be a signed integer, unsigned integer, or a single precision floating point number.
 
I would recommend looking at the type cast function, that will take a string representing 4 bytes and convert it to a numeric value depending on the representation of the constant you wire into the top of it.
Message 2 of 18
(9,883 Views)
Use a typecast function.I will suggest u try string to bytearray function.Here u can input ascii values and get its equivalent decimal values.For checking purpose u can try this.
Message 3 of 18
(9,861 Views)
Sorry for not providing enough information. Here's my 2nd attempt,
I am reading a signed hex string, for example FFFFFFB0, and need to convert this hex string to its decimal equivalent. In this specific case, it should be -80. The expected values may fall the range of -50 to -120. When I tried the various methods suggested, I am always ending up with 0. I am using LV 7.0, so most of the examples could not be opened for me to examine and explore the other methods suggested. Here is one of the example code with my "hex string value". Thanks for any help that anyone can provide.
0 Kudos
Message 5 of 18
(9,804 Views)
There is a big difference between a hex string and a string that's in hex display mode. What you have is the latter. This means you need to use the TypeCast function:



Also, why are you trying to convert what is supposedly a 32-bit value to an 8-bit value? Smiley Surprised


Message Edited by smercurio_fc on 06-16-2008 10:54 AM
0 Kudos
Message 6 of 18
(9,801 Views)
I'm not sure why you have a 4.x version of the typecast function.  But you need to wire a constant of the appropriate datatype to the top of it.  In this case an I32.  Now you have an I32 number.  If you want that as a string, you can use the number to string functions to format it.
 
Edit:  I see Smercurio got a similar response in while I was distracted while writing my post.
 


Message Edited by Ravens Fan on 06-16-2008 12:10 PM
0 Kudos
Message 7 of 18
(9,797 Views)
I'd like to thank both Smercurio and Ravens Fan, looking through both emails I now have what I need. Although, I'd like to have some statements clarify so I may understand LV a bit better. The VI in question is to monitor some data bytes coming via UDP. Embedded within the UDP data frame, I needed to monitor specific bytes (hex string) for the conversion. Question 1- the UDP data is in hex code, so the string function just to make the data more user friendly was to display in hex mode. Originally, the requirements was to use a 32-bit signed hex code, this was latter changed, when the 'designers' forgo the 32-bit and opted for just a 2-byte code. I still needed to convert with I32 data type to get the sign correct, as it seems. I still didn't get the correct decimal number when used in this way though, but I needed the decimal format in string type. Please see the attached as reference. It seems to work now, thanks again for the help.
0 Kudos
Message 8 of 18
(9,782 Views)
Unfortunately, I didn't quite understand what you're trying to say here. You say:

@dglee359 wrote:
Originally, the requirements was to use a 32-bit signed hex code, this was latter changed, when the 'designers' forgo the 32-bit and opted for just a 2-byte code. I still needed to convert with I32 data type to get the sign correct, as it seems. I still didn't get the correct decimal number when used in this way though, but I needed the decimal format in string type. Please see the attached as reference.

Your code only looks at 1 byte, and for that matter it looks at the second byte of what you get from the UDP Read. Yet you say you have a 2-byte code. I don't know what you mean by "I still didn't get the correct decimal number when used in this way though" since it's not clear what you're referring to.

Aside: Learn about the shift register, as you can use it instead of the local variables:





Message Edited by smercurio_fc on 06-16-2008 12:02 PM
0 Kudos
Message 9 of 18
(9,776 Views)


dglee359 wrote:
Embedded within the UDP data frame, I needed to monitor specific bytes (hex string) for the conversion. Question 1- the UDP data is in hex code, so the string function just to make the data more user friendly was to display in hex mode. Originally, the requirements was to use a 32-bit signed hex code, this was latter changed, when the 'designers' forgo the 32-bit and opted for just a 2-byte code. I still needed to convert with I32 data type to get the sign correct, as it seems. I still didn't get the correct decimal number when used in this way though, but I needed the decimal format in string type. Please see the attached as reference. It seems to work now, thanks again for the help.

  • A string is just a string. While this particular string display is set to hex display, it does not change the underlying data.
  • You are only extracting a 1byte subset, so the best you can get out of it is a I8 (that is what you currently have) and it includes a sign.
  • If you want a 2byte code with sign, get a 2 byte subset and cast it to I16.
  • Your code still makes absolutely no sense in relation to what you actually describe.
  • Converting to a fractional format string is inappropriate for integers, use "number to decimal string".
  • The "cnt" belongs into a shift register instead of local variables.

0 Kudos
Message 10 of 18
(9,770 Views)