how to swap the high-byte and the low-byte?
there is a binary file in unix OS, I want to read it at windows OS, there must be to swap the byte sequence of the int or float type data.
to int, with follow code:
"
short n;
short i,j,k=0x00ff;
i=n<<8;
j=n>>8;
j=j&k;
n=i|j;
"
compile with error:
"
can not convert type 'int' to type 'short'
"
why?
how about float to be swapped?
in c++, that is easy!
we just do it with union!
like this
"
void TransFloat(float *f)
{
union {
float i;
unsigned char c[4];
} a;
unsigned char tmp;
a.i=*f;
tmp=a.c[0];
a.c[0]=a.c[3];
a.c[3]=tmp;
tmp=a.c[1];
a.c[1]=a.c[2];
a.c[2]=tmp;
*f=a.i;
return;
}
"
but in c#, swap float type data may be difficult,
somebody can help me?
thx!