From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Hex String to Number Conversion...always unsigned?

Hi All,

 

Found this baffling issue to me:

 

UUT Readback:    Failed
        Measurement:              0x999fffdf
        Limits:
           Low:                   0x999fffdf
        Comparison Type:          EQ (==)
        Module Time:              0.0414499

 

I did a numeric limit test on an UUT readback...then realized even though the HEX number is right, I always fail...what the?

So what I do is, I read information from another part of the UUT at 4 memory locationsand it spits out that in 8bit chucks (Let's call these 4 datas: A, B, C,D). My Numeric Test is comparing all the information at once in a 32bit word from yet another memory location (data Z), so I end up converting each UUT memory location readback to a HEX string, then doing a "+" operation so it will be appended instead of just doing a normal arithematic addition.

 

At the end I get "99"+"9f"+"ff"+"df" = "999fffdf" or A+B+C+D = "999fffdf" , then I do a val("0x"+ "999fffdf") and I get a Hex Number out.  However, I have noticed in my investigation of this failure that the converted A+B+C+D is always an unsigned number.  So when TS does the compare to data readback from Z, even though the HEX are the same, the test always fails.  I have tried to set the values to numeric format unsigned and it does nothing, always a failure. 

 

Is there a way for me to convert HEX Strings to Hex Number while keeping the sign?

 

Regards,

mwc

 

0 Kudos
Message 1 of 8
(7,529 Views)

I think you may need to try the following:

 

Locals.TestNumber = Int64(Val("0x"+ "999fffdf"))

 

Just be sure TestNumber is represented as a Signed 64-bit integer.

 

 

HowToConvert.png

Jared A.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(7,509 Views)

Good Morning Jared,

 

I should have mentioned I am on Teststand 4.2 

 

I am guess the Int declaration is on TS 2010 or later?  I do not find any support to this call in 4.2

 

Regards,

mwc

0 Kudos
Message 3 of 8
(7,482 Views)

After looking into this some more, I determined how to configure TestStand to successfully compare the hexadecimal values.


Under the Data Source Expression of the Numeric Limit Test, you must wrap the returned value in the Val() function as so:


Val(Step.Result.Numeric)


This is necessary if you are returning an integer from LabVIEW.

 

1.png

 

2.png

Jared A.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(7,462 Views)

The problem is that TestStand number variables are really floating point numbers so that when you convert "0xFFFFFFFF" for example, it doesn't know you want a signed value. It assumes you want unsigned, so converts it to the unsigned equivalent.

 

I do not think Val() will help you in this case, I think Jared was correctly getting a signed-integer becase that is the data type for his VI parameter.

 

I think the easiest thing for you to do is to write a code module to convert the string to a signed-integer (or to convert the unsigned value to its signed integer equivalent) rather than doing so directly in teststand. If you return the signed-integer value back to teststand as a signed-integer parameter of a code module, teststand will correctly store the signed value in a TestStand Number variable. You can write a pretty simple VI or C or C# function which does this and call it to do the string conversion or unsigned to signed conversion.

 

You might want to write an idea exchange post to recommend TestStand add a feature to support converting hex strings into signed-integers directly.

 

Hope this helps,

-Doug

0 Kudos
Message 5 of 8
(7,450 Views)

Hi Alll,

 

I know that this topic was started many years ago, but I had the same issue nowadays and was not able to find any solution.
Finally I was able to figure out a solution works to me.

Therefore I present my solution here maybe others will find this topic in the future and it can help.
My task was to covert hex string which store the value in 16-bit signed format.

 

The value stored in string is -265  (0xFEF8).

 

Step.Result.Numeric = Val("0x" + "FEF8" ) ,
Step.Result.Numeric =

Step.Result.Numeric > 0x7FFF ? ( Float64(0xFFFFFFFFFFFF0000i64 + Int64(Step.Result.Numeric)) ) :  Step.Result.Numeric

 

Regards

0 Kudos
Message 6 of 8
(4,184 Views)

Here is my solution in a single line: Convert 2Byte Hex to Integer

256*Locals.Byte_hi + Locals.Byte_lo - (Locals.Byte_hi > 0x7f ? 0x10000 : 0)

 

By the way "-265 is not "0xFEF8"

2021-02-08.png

 

 

0 Kudos
Message 7 of 8
(3,615 Views)

If you need to convert string containing hex integer (two's complement), which is not 64 bit (e.g. 16 bit integer), you can try bitwise shifts like this: Int64("0xFEF7" /*Input Example*/) << (64 /*TS number bits*/ - 16 /*Custom number bits*/) >> (64 /*TS number bits*/ - 16 /*Custom number bits*/). The example shall return -265.

 

Or in short: Int64("0xFEF7" /*Input Example*/) << 48 >> 48.

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.
0 Kudos
Message 8 of 8
(2,825 Views)