LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there something like swab in LabWindows

Hi,
I need to swab bytes to handle BIG / LITTLE ENDIAN.
Is in LabWindows something like
void __cdecl swab(char *, char *, int);
available (didn't find it yet)
THX
0 Kudos
Message 1 of 2
(2,594 Views)
No that I know of. But you can do it with either of the following two methods (assuming you are trying to convert Little Endian to Big Endian):

Method 1 - For Loop:

#include
#include

main()
{

short, int data[32];
int;

for (i = 0; i < 32; i++) {
char temp;
temp = (char) (data[i] & 0xFF00) >> 8);
data[i] = (data[i] << 😎 & 0xFF00;
data[i] = data [i] | temp;
}

Method 2 - CVI's Scan function:

Scan (data, "%32i[b2] > %32i[b2o10]", data);

The number of bytes modifier [b2] modifier simply tells the Scan function that the data is short (2-byte int). The order modifier,[o10], tells the Scan function that the byte order is [10] or a descending order of precedence as compared to [01], which would be an ascending o
rder of precedence.

Take your pick.

Regards,
Azucena
0 Kudos
Message 2 of 2
(2,594 Views)