Example Code

Convert String Hex to Integer Decimal in LabVIEW

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

Demonstrates how to convert string's hexadecimal representation to integer decimal equivalent.

 

Description

The example uses converts individual ASCII string characters to their decimal equivalents and then to their hexadecimal equivalents. These hex equivalents are returned as strings. The hex equivalents are concatenated into an unbroken set of digits. The resulting set of digits is identical to that seen in the Hex String Input except without the spacing. The set of hex digits is converted to their decimal equivalent and displayed. 

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Key in hexadecimal integer value, limited to Hex Display
  2. Run the program
  3. The integer decimal equivalent will be displayed

 

Additional Information or Resources

VI Block Diagram

BD.png

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

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

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

Just using Type Cast would be a lot easier...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Poolean
Member
Member
on

This is something I was playing around with for a while and I couldn't figure out another way to get the conversion to work. Would you mind showing how you'd do this with a Type Cast?

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Since we are dealing with a U64 in the end, we first need to make sure we have 8 bytes in our string.  From there, it is just a simple Type Cast to a U64.

I also fixed a couple of bugs I found in your code while doing comparisons.  If we have more than 8 bytes in the string, your code will just max out the U64.  Also, try putting in a 0x01 in your code and it turns into a single character when it should be 2.

I'll let you decide which on looks simpler, but I know mine will be more efficient.

String Hex to Interger Decimal_BD.png


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Poolean
Member
Member
on

That's a clever way to handle it. And, you're right; your way is definitely more efficient.Thanks for posting that!