Why Doesn't the Hexadecimal String to Number VI Convert Data Properly?

Updated Nov 12, 2018

Reported In

Software

  • LabVIEW

Issue Details

I am using the Hexadecimal String to Number VI to convert my Hexadecimal Data and I either get a zero or the wrong answer. Why is my Hex value not being converted properly?

 

Solution

The Hexadecimal String to Number VI expects a number without the ‘0x’ prefix, which is present in raw hexadecimal data.
  • For example, if you input “5555”, it will return the decimal value 21845, which is the correct decimal representation of the hexadecimal value 0x5555.
  • However, if you input “0x5555”, it will return 0. This is because the raw hex value 0x5555 actually corresponds to an ASCII string of “UU” which is not a number, thus it returns a 0.
If you want to resolve this, while keeping raw hexadecimal input, you can Type Cast the value using the Type Cast VI. You will need to type cast it as a 16-bit integer.

Additional Information

Check the string at the input of the VI to make sure it does not contain any hidden or escape characters. If it contains escape characters, it is possible that the VI will return a 0 or incorrect value.