点击(此处)折叠或打开
void swap1(int *rhs)
-
-
{
-
unsigned char *p=rhs;
-
unsigned char temp;
-
temp=p[0];
-
p[0]=[1];
-
p[1]=temp;
-
-
temp=p[1];
-
p[1]=[2];
-
p[2]=temp;
-
return ;
-
}
-
-
void swap2(int *rhs)
-
{
-
*rhs=(((*rhs)&0xff000000)>>24) | (((*rhs)&0x00ff0000)>>8) | (((*rhs)&0x000000ff)<<24) | (((*rhs)&0x0000ff00)<<8);
- }
int check1()//检查主机字节顺序是否是大端法,如果是,返回1,否则返回0.
{
int i=0x12345678;
unsigned char *p=&i;
return (0x12==p[0]);
}
int check2()
{
union{
unsigned int i;
unsigned char s[4];
}c;
c.i=0x12345678;
return (0x12==c.s[0]);
}