NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting from 32bit Hex to Decimal Floating-Point

I need to use an already written VI that returns two U16 words (Output_1, Output_2). How do I combine these words and convert to a 32bit decimal floating-point number in a post expression for use in a numeric comparison? Is there a way to do something similar to the labview type-cast function in TestStand? I think the expression should start with something like this Step.result.Numeric = Locals.Output_1*65535 + Locals.Output_2.

I'm using TestStand 3.5

Thanks,
Jason
0 Kudos
Message 1 of 8
(6,837 Views)

Jason,

 

You can try this:

 

Locals.OutputValue = (Locals.One << 16) | Locals.Two

 

I did this with the following values and let TestStand do the conversion, since all values in TestStand are stored as doubles regardless of viewing format:

 

My watch expressions showed the following:

Locals.OutputValue = 2271560481.000000 // formatted as Real
Locals.One << 16 = 0x87650000 // formatted as "0x#.8X"
Locals.Two = 0x00004321 // formatted as "0x#.8X"
Locals.OutputValue = 0x87654321 // formatted as "0x#.8X"
(Locals.One << 16) | Locals.Two = 0x87654321 // formatted as "0x#.8X"

 

I think you are on the right track, and TestStand will convert what you want.

 

-Jack

 

Message 2 of 8
(6,828 Views)

Hi

 

Try this example

 

 

Greetings

juergen

 

Seems I was to slow. Excatly the same as Captain Jack !

Message Edited by j_dodek on 11-21-2008 01:32 AM
--Signature--
NIWeek 2017: Standardized HIL Test Automation With TestStand
NIWeek 2016: Capturing ATE Requirements With Requirements Gateway

Feedback or kudos are welcome
Download All
0 Kudos
Message 3 of 8
(6,821 Views)
I'm able to combine the words correctly but can't get the correct conversion. If the low word is 0x6667 and the high word is 0x416E the correct conversion from 32-bit hexadecimal to decimal floating-point according to IEEE-754 is 14.9000....... I keep getting 1097754215 which is a hex to decimal conversion.
0 Kudos
Message 4 of 8
(6,810 Views)

Hi,

 

that means your hole dword is repesenting a 32bit float ?

addtional http://de.wikipedia.org/wiki/IEEE_754

 

in C/C++

i would call this function;

float toFloat(WORD wLow, WORD nHigh)

{   union{

   WORD[2] warray;

   float fVal;

   } myUnion;

 myUnion.warray[0] = wLow;

 myUnion.warray[0] = nHigh;

 return myUnion.fVal;

}

 

juergen

Message Edited by j_dodek on 11-21-2008 09:48 AM
--Signature--
NIWeek 2017: Standardized HIL Test Automation With TestStand
NIWeek 2016: Capturing ATE Requirements With Requirements Gateway

Feedback or kudos are welcome
0 Kudos
Message 5 of 8
(6,794 Views)

I see, you don't want to treat the 16bit integers as integers, you want to reinterpret them as the binary bits of a 32-bit floating point number. Not sure if there is a way to do this in a LabVIEW VI (perhaps someone who knows LabVIEW better than me can help if needed), but you can do this in a C/C++ DLL as follows:

 

float ConvertBitsToFloat( unsigned short highbits, unsigned short lowbits)

{

     float retval;

     DWORD * floatbits = (DWORD *) &retval;

     *floatbits =  ((DWORD) highbits << 16) | (DWORD)lowbits;

 

    return retval;

}

 

Hope this helps,

-Doug

0 Kudos
Message 6 of 8
(6,787 Views)
I know I can do this conversion in Labview using the type cast funtion, but I don't want to change the already written VI. Is there a way to do the above C/C++ commands in a post expression in TestStand?
0 Kudos
Message 7 of 8
(6,783 Views)

You cannot do a reinterpret cast in the TestStand expression language. You could parse the exponent and the mantissa out of the 32-bits and use floating point arithmetic and functions to recreate an equivalent value, but it would be tricky, especially if you want to support corner cases like INF, IND, and NAN.

 

If you think you know how to do the conversion in LabVIEW already, I'd recommend just writing a utility VI in labview which does this and call that from TestStand. There's no need to modify existing VI, you just need to write a new one to do the conversion.

 

Hope this helps,

-Doug

0 Kudos
Message 8 of 8
(6,775 Views)