How to Convert Between Hexadecimal and ASCII in LabVIEW?

Updated May 3, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

I am communicating with an instrument that sends back information in the form of hexadecimal values.  For instance, instead of sending the letter L, it sends back its corresponding hexadecimal representation 4C. How can I programmatically convert this hexadecimal representation into its corresponding ASCII representation in LabVIEW? What if I need to send information back to the instrument in hexadecimal?

Solution

Converting to ASCII from Hexadecimal

To convert a hexadecimal string into an ASCII string, you must first convert the hexadecimal string to its decimal representation using the Scan Value function, which is found in the functions palette under Programming»String»String/Number Conversion.  You can then convert the decimal representation to its ASCII string equivalent using the Type Cast function, found in the Functions Palette under Mathematics»Numeric»Data Manipulation.

Converting to Hexadecimal from ASCII

To convert a ASCII string into a hexadecimal string, you must first convert the ASCII string to its decimal representation using the Type Cast function, which is found in the functions palette under Mathematics»Numeric»Data Manipulation. You can then convert the decimal representation to its hexadecimal string equivalent using the Number to Hexadecimal String function, found in the Functions Palette under Programming»String»String/Number Conversion. 

 

Additional Information

The hexadecimal string input for the following VIs are in the form FF not 0xFF. The 0x is the convention for indicating that a number is hexadecimal based rather then decimal based. A standard hexademical string does not carry this indicator, and it must be removed before the value can be translated. This behavior is identical to the Hexadecimal String to Number VI and is expected.  If you have strings which have the 0xFF format you can use a Search/Split String VI with a search character of x before the string is passed to the Scan Value VI.

WAS THIS ARTICLE HELPFUL?

Not Helpful