#include <iostream>
#include <stdio.h>
typedef union{
unsigned short value;
unsigned char bytes[2];
}Test;
int main(int argc, const char * argv[]) {
Test test_value;
test_value.value = 0x1234;
if(test_value.bytes[0] == 0x12 && test_value.bytes[1] == 0x34)
printf("big ending\n");
else if(test_value.bytes[0] == 0x34 && test_value.bytes[1] == 0x12)
printf("little ending\n");
else
printf("use test_value error");
int num = 0x12345678;
char *p = (char *)#
if (p[0] == 0x78) {
printf("little ending\n");
} else if(p[0] == 0x12){
printf("big ending\n");
}
printf("%x,%x,%x,%x\n", p[0],p[1],p[2],p[3]);
return 0;
}
输出
little ending
little ending
78,56,34,12