09-28-2011 11:07 AM
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!
Solved! Go to Solution.
09-28-2011 11:48 AM
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.