endBian

2017-01-13 08:23:11来源:CSDN作者:ll352071639人点击

int num = 0x12345678;

big endBian:

...0x990x1000x1010x1020x1030x104...
...0x120x340x560x78..


little endbian:

..0x990x1000x1010x1020x1030x104..
...0x780x560x340x12...


#include <stdio.h>#include <stdlib.h>#include <memory.h>int a = 0x12345678;char arr[sizeof(int)];int main(){		memcpy((void *)arr, (void *)&a, sizeof(int));	printf("a address:%p/n", &a);	char *tmp = arr;	do	{		printf("0x%x/n", *tmp);	}	while(*tmp++);	char *tt = (char *) &a;	printf("&tt[0]%p,/t&tt[1]%p,/t&tt[2]%p,/t&tt[3]%p/n", &tt[0], &tt[1], &tt[2], &tt[3]);	printf("tt[0]0x%x,/ttt[1]0x%x,/ttt[2]0x%x,/ttt[3]0x%x/n", tt[0], tt[1], tt[2], tt[3]);	return 0;}

output:

lang@langdesktop:~/Learn/endDian$ gcc test.c
lang@langdesktop:~/Learn/endDian$ ./a.out
a address:0x601040
0x78
0x56
0x34
0x12
0x0
&tt[0]0x601040,    &tt[1]0x601041,    &tt[2]0x601042,    &tt[3]0x601043
tt[0]0x78,                   tt[1]0x56,              tt[2]0x34,                tt[3]0x12




相关文章

    无相关信息

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台