免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 14051 | 回复: 0
打印 上一主题 下一主题

little endian和big endian的概念解释,判定与用途 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2006-09-05 21:40 |显示全部楼层
ittle endian:0xcdab3412,即0x00000000-0xcd,0x00000001-0xab,0x00000002-0x34,0x00000003-0x12

little endian把低位存放到高位

上面的说反了吧.little endian应当是
0x00000000-0x12
0x00000001-0x34
....
这样的吧.

little endian把低字节存放到低地址,把高字节放到高地址.
数据0xcdab3412从左到右,由高字节到低字节,由高地址到低地址.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>

  4. int main()
  5. {
  6.     int value = 0x12345678;

  7.     union ValueT
  8.     {
  9.         int value;
  10.         char data[4];
  11.     } a;
  12.     a.value = 0x12345678;
  13.     printf("value is 0x%x\n", a.value);
  14.     printf("address is %p, 0x%x\n",&a.data[0], a.data[0]);
  15.     printf("address is %p, 0x%x\n",&a.data[1], a.data[1]);
  16.     printf("address is %p, 0x%x\n",&a.data[2],  a.data[2]);
  17.     printf("address is %p, 0x%x\n", &a.data[3], a.data[3]);

  18.     exit(EXIT_SUCCESS);
  19. }
复制代码

value is 0x12345678
address is 0xbffffa0c, 0x78
address is 0xbffffa0d, 0x56
address is 0xbffffa0e, 0x34
address is 0xbffffa0f, 0x12

[ 本帖最后由 coldwarm 于 2006-9-5 21:56 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP