LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting to Double using Big-Endian Format in CVI

Hi Folks,

I'm trying to dump the cal coefficients from an HP 8751A RF network analyzer using LabWin/CVI.   I'm using VISA across the GPIB.  The highest precision data is available in 64-bit doubles.  Unfortunately, it is in Big-Endian Motorola format.  I've studied the "Floating Point Modifiers" for the CVI "Fmt" command, but it appears that the Fmt command only allows byte swapping for Integer data using the "o" modifier (e.g. o1234, etc).  Is there an elegant way to swap the incoming Big-Endian bytes (all eight of 'em) to properly read in a double float?  I imagine that there is.  I can't be the first guy to want to pull a double from an older HP device.

I noticed that HP provided a lower resolution little-endian 32-bit float format to solve this type of issue with the 8751A.  Unfortunately, the lower precision of the 4-byte floats causes unacceptable error for reflection measurements (i.e. 30-40 db vice 70-80 db S11 measurements).

Thanks, calvin
0 Kudos
Message 1 of 2
(3,453 Views)
See if the following helps. The test function returns a double with opposite byte order.
 
#include <utility.h>
#include <formatio.h>
#include <ansi_c.h>
 
double test(double dbl)
{
 int    intBuffer[sizeof(double)/sizeof(int)],
        intBuffer2[sizeof(double)/sizeof(int)];
 double result;
 
 memcpy(intBuffer, &dbl, sizeof(intBuffer));
 Fmt(&intBuffer2[1], "%i[o3210]<%i", intBuffer[0]);
 Fmt(&intBuffer2[0], "%i[o3210]<%i", intBuffer[1]);
 memcpy(&result, intBuffer2, sizeof(result));
 return result;
}
 
void main(void)
{
 __int64 i64 = 0x0A0B0C0D0E0F0102;
 double  dbl1, dbl2;
 void    *p1 = &dbl1, *p2 = &dbl2;
 
 // assign a nice pattern to the double for testing
 memcpy(&dbl1, &i64, sizeof(double));
 dbl2 = test(dbl1);
 
 // look at p1 and p2 in memory window to check byte order
 Breakpoint();
}
0 Kudos
Message 2 of 2
(3,432 Views)