NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert number to hex string within function statement?

Solved!
Go to solution

I saw a few posts asking how to convert a hex string into a number, however I didn't see anything regarding going the other direction - how to convert a number back into a hex string. Can TestStand convert a number into a hex string within a function?

 

Here's what I'm trying to do (Locals.CryTuneHex is a string with a hex value represented and Locals.Freq_Meas is a numeric):

 

Locals.CryTuneHex = Val("0x" + Locals.CryTuneHex) + Round(((320000 - Locals.Freq_Meas)/0.065),4)

 

or in simpler terms:

Locals.HexString = Locals.DecimalNumber

 

I need to convert the right side of the equation (which is a decimal number) to a hex string in order to store it back to the String variable on the left side of the equation. Is this possible? I see there is a Str() operator to convert to a string, but I need it in hex, not just a string representation of the decimal number.

 

Thanks!

0 Kudos
Message 1 of 2
(17,570 Views)
Solution
Accepted by topic author Raydur

Pass a format to Str, like  locals.HexString = str(Locals.Number, "%x")

 

To play with format strings, create a local number, right click and select Numeric Format, and then choose Hexadecimal for Type and watch how the format string varies as you change the options.

Message 2 of 2
(17,567 Views)