编程判断当前处理器使用的大端模式还是小端模式?
思路一:
int a=0x12345678;
char *p = (char *)&a;
if(*p == 0x12)
printf("大端");
思路二:
union
{
int a;
char buf[4];
}test;
test.a=1;
if(test.buf[0] == 1)
printf("小端");
思路一:
int a=0x12345678;
char *p = (char *)&a;
if(*p == 0x12)
printf("大端");
思路二:
union
{
int a;
char buf[4];
}test;
test.a=1;
if(test.buf[0] == 1)
printf("小端");
void my_itoa(int num,char tmp[]
{
int i=0,j=0;
char temp[128]={0};
if(num<0)
{
num=-num;
}
for(i=0;i<12;i++)
{
temp[i]=num%10+'0';
num =num/10;
if(num ==0)
{
break;
}
}
for(j=0;j<=i;j++)
{
tmp[j]=temp[i-j];
}
tmp[j+1]='\0';
printf("%s\n",tmp);
}