Converting a Hex String to a Normal String in LabVIEW

Updated Jan 15, 2019

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional

Issue Details

I have string control represented as Hex Display.  How can I convert it to a normal string indicator while keeping the hexadecimal notation?

Solution

In order to convert a hex string into a normal string you need to do the following:
1. Convert the hex string into a byte array.  This converts the hex string into an array of smaller hex strings of two digits.
2. Concatenate the smaller hex strings into a normal string.
3. Check for the string length and prepend 0 if it has only one character.  This will result in a proper conversion from hexadecimal to normal string in the case that a two digit hex string starts with zero.

Figure 1 shows a possible implementation of the above steps.
Figure 1. Code for converting a hex string to a normal string.
Another method for converting a hex string to a normal string is to:
1. Convert the hex string into a byte array.
2. Format the byte array into a string using the Format into String function with a value of %x for the Format String parameter.
3. Change the Format String parameter to 0%x in the case that a byte starts with zero.

Figure 2 shows a possible implementation of the above steps.
Figure 2. Code for converting a hex string to normal string using Format into String VI.

WAS THIS ARTICLE HELPFUL?

Not Helpful