little endian vs big endian# Programming - 葵花宝典
l*l
1 楼
//Please tell me what's the output of the following code for
//bothe little endian and big endian.
#include
#include
int main(void)
{
unsigned long a[2];
unsigned short c;
unsigned char* b;
a[0] = 0x12345678;
a[1] = 0x9abcdef0;
b= (unsigned char*)a;
printf("%02x%02x%02x%02x%02x%02x%02x%02x\n",b[0],b[1],b[2],b[3],
b[4],b[5],b[6],b[7]);
b += 2;
printf("%x\n", *(unsigned int*)b);
b += 4; //b = a+6
printf("
//bothe little endian and big endian.
#include
#include
int main(void)
{
unsigned long a[2];
unsigned short c;
unsigned char* b;
a[0] = 0x12345678;
a[1] = 0x9abcdef0;
b= (unsigned char*)a;
printf("%02x%02x%02x%02x%02x%02x%02x%02x\n",b[0],b[1],b[2],b[3],
b[4],b[5],b[6],b[7]);
b += 2;
printf("%x\n", *(unsigned int*)b);
b += 4; //b = a+6
printf("