Example Code

Convert a HEX Value String to a String With The Hex Value

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example parses an ASCII input string, removing the characters that aren't valid HEX characters, and then converts the remaining bytes into a binary string based on those HEX values.

 

Description

In some situations, you may need to use strings to describe a HEX value, but then need to convert that string into an arbitrary string which is that HEX value. This process is less intuitive then you may expect. Moreover, it is complicated to create a function that scales well and allows an arbitrary length of string to convert. This VI will take in any string and will parse the HEX characters from it, and then convert just those HEX values into a new string that is defined by those values. The resultant string is of an arbitrary length.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Format your HEX string according to any convention you prefer. The input string is conditioned to remove any characters that are not 0-9, a-f or A-F.
  2. Run the VI.

 

Additional Information or References

 

 VI Snippet

1.png

 

Note that the resultant string may include a zero hex value appended to the end if your input ASCII hex values do not translate into a multiple of 8 bits (for example, if you input 3 hex characters, the number of bits required to implement those values is 12, but an ASCII character is 8 bits, and so can only do multiples of 8. The resultant string will be 16 bits.)

 

A much simpler and more flexible implementation can be found in the following example.

Convert a String Which Describes a HEX Value to an Arbitrary String That is The HEX Value

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Asa Kirby
CompactRIO Product Marketing Manager
________________
Sail Fast!

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
JmBone
Member
Member
on

Thank you so much for this. It works great and has helped me tremendously.

makagun
Member
Member
on

Thank you for good information. I feel grateful to copy your information in other sites.