small-endian to big-endian conversion of data to store in a structure
Hi
I transfer 7 kb binary data from a windows OS to a linux OS(uST-SH2 cpu, which is big-endian).
I am trying to store the data in some structure at the linux side. At the sender end I write the data stored in structure to a file and then read data from the file to transfer finally.
At the receiver end, first of all complete data is received in a large size buffer and then data from buffer is used to assign to the variables of the structure.
On the windows side variables of structure are defined as ULONG
On the linux side variables of structure are defined as unsigned long
I am not able to store the data in the structure in a correct sequence, though I have written a small code to convert the small-endian format data into big-endian format.
here is the small portion of the code, which I am using to convert small endian to big-endian
BYTE local_val ;
size // this parameter specifies the total number of data bytes received
// convert the data from small endian to big endian
for(k=0;k<size;k=k+4){ local_val = MUXDataBuff[k] ;
MUXDataBuff[k] = MUXDataBuff[k+3] ;
MUXDataBuff[k+3] = local_val ;
local_val = MUXDataBuff[k+1];
MUXDataBuff[k+1] = MUXDataBuff[k+2] ;
MUXDataBuff[k+2] = local_val ;
}
Kindly help to solve this issue.
Thanks
Nancy
|