02-26-2004 02:09 PM
02-27-2004 11:35 AM
02-27-2004 01:31 PM
03-02-2004 02:16 PM
03-02-2004 02:30 PM
03-05-2004 04:51 PM
10-15-2014 12:14 PM - edited 10-15-2014 12:15 PM
@craigherdman wrote:
The following are snippets from the NI LabWindows/CVI Help files included with CVI.
short int instr_buf[100]; short int prog_buf[100]; status = ibrd (ud, instr_buf, 200); Fmt (prog_buf, "%100d<%100d[b2o01]", instr_buf);
This sample code from the help file results in a "Parameter type incompatible with format specifier". The problem is the specifier "i" assumes 4-byte normal integers. So a modifier of [b2] must be used. Here's the correct code:
short int instr_buf[10] = {1234, 9421, 0x279, 0}; // sample data short int prog_buf[10] = {0}; Fmt(prog_buf, "%10i[b2]<%10i[b2o10]", instr_buf);
10-15-2014 01:12 PM
Or you can do it manually using a union...
Using the union you can manipulate the bytes any way you want.
union UNION_4_BYTES
{
float f32;
int i32;
unsigned int u32;
int en; // enum type
short s16[2];
unsigned char byte[4];
};
union UNION_4_BYTES source32bitNum, target32binNum;
source32bitNum.i32 = 123;
target32bitNum.byte[0] = source32bitNum.byte[3];
target32bitNum.byte[1] = source32bitNum.byte[2];
target32bitNum.byte[2] = source32bitNum.byte[1];
target32bitNum.byte[3] = source32bitNum.byte[0];
// your target byte swapped value is in target32bitNum.i32
10-16-2014 08:52 AM - edited 10-16-2014 08:53 AM
I don't understand all those specifiers in the Fmt and Scan commands. I would just do it the old-fashioned way:
int* i = (int*)&myFloat; *i = ((*i & 0xff000000) >> 24) | ((*i & 0x00ff0000) >> 8) | ((*i & 0x0000ff00) << 8) | ((*i & 0x000000ff) << 24);