04-10-2013 09:16 AM - edited 04-10-2013 09:18 AM
Hello,
I ran the following sample code:
//////////////////////////
OutboundMsg.Header.Msg_ID = ToBigEndian32(FOO_MSG_ID);
DebugPrintf(“FOO_MSG_ID: %d”, FOO_MSG_ID);
DebugPrintf(“NATIVE: %08X”, FOO_MSG_ID);
DebugPrintf(“BIG ENDIAN: %08X”, OutboundMsg.Header.Msg_ID);
DebugPrintf(“LITTLE ENDIAN: %08X”, ToLittleEndian32(OutboundMsg.Header.Msg_ID));
DebugPrintf(“LITTLE ENDIAN??? %08X”, ToBigEndian32(OutboundMsg.Header.Msg_ID));
///////////////////////////////
And here is the output:
FOO_MSG_ID: 30
NATIVE: 0000001E
BIG ENDIAN: 1E000000
LITTLE ENDIAN: 1E000000
LITTLE ENDIAN??? 0000001E
The line in red shows that the call to ToLittleEndian32 did no byte swapping. Instead, only ToBigEndian32 actually did any byte swapping. CVI says that a failed call to these endian functions will return 0. It should not return exactly what was passed into it, as I’m seeing here.
Or am I missing something?
Thanks!
Tim O'Leary
Solved! Go to Solution.
04-10-2013 09:39 AM
Functions dealing for endianness are located in toolbox instrument, whose code is distributed so you can check them by yourself.
As you can see here:
unsigned int CVIFUNC ToLittleEndian32(unsigned int n) { if (HostIsLittleEndian()) return n; return ToOtherEndian32(n); }
the function tests for system endianness and returns original number if the system is already little endian, which appears to be your case. This appears a correct behaviour to me.
The only condition for returning 0 is that ToOtherEndian32 () cannot discriminate system endianness; in every other case a number is returned.