Little-endian or Big-endian

二进制存储的文件,多字节(例如四个字节的word)常常存在 Little-endian or Big-endian的问题,单字节的数据类型是不存在该问题的,所有的计算机字节的存储方式是完全相同的。

Little-endian or Big-endian出自《格列夫游记》,小人国的人争论从大头还是小头砸开鸡蛋。

    By the way, the big-endian / little-endian naming comes from Gulliver's Travels, where the Lilliputans argue over whether to break eggs on the little-end or big-end. Sometimes computer debates are just as meaningful :-)

摘自Understanding Big and Little Endian Byte Order
Big endian即先存高位字节。
Little endian即先存低位字节。

Big endian machine: Stores data big-end first. When looking at multiple bytes, the first byte (lowest address) is the biggest.
Little endian machine: Stores data little-end first. When looking at multiple bytes, the first byte is smallest.

最明确的办法是,逐个字节的存储,这样的代码在任何机器上都不会有歧义:

c = 0;     // point to location 0 (won't work on a real machine!)
*c = 0x12; // Set W's value
c = 1;     // point to location 1
*c = 0x34; // Set X's value
...        // repeat for Y and Z; details left to reader
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值