69,373
社区成员
发帖
与我相关
我的任务
分享
union {
int a;
char b[sizeof(int)];
}test;
test.b[0]=1;
test.b[1]=2;
test.b[2]=3;
test.b[3]=4;
#include <iostream>
using namespace std;
bool checkSystem()
{
union check
{
int i;
char ch;
}
c;
c.i =1;
return(c.ch == 1);
}
int amen(void)
{
if(checkSystem()) cout << "Little Endian" << endl;
else cout << "Big Endian" << endl;
return 0;
}
#include <stdio.h>
int main()
{
int i = 0x1234;
char *p = (char*)&i;
printf ("the first %x\n", *p);
printf ("the first %x\n", *(p+1));
return 0;
}
short int s=0x1234;
if (0x34==*((char *)&s)) printf("Little Endian\n");
else printf("Big Endian\n");
LONG a=0X12345678;
cout<<a<<endl;
LONG b=htonl(a);
cout<<b<<endl;
cout<<"如果a和b输出一致,则是:大端,否则是小端"<<endl;