加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

MATLAB中fopen的“ieee-be”和“ieee-le”

(2013-03-03 19:50:46)

ieee-be : big endian

ieee-le : little endian

Byte Ordering

Microprocessors support big-endian and little-endian byte ordering. Big-endian is an order in which the "big end" (most significant byte) is stored first (at the lowest address). Little-endian is an order in which the "little end" (least significant byte) is stored first.

The table below shows the representation of the hexadecimal number 0x0AC0FFEE on a big-endian and little-endian machine. The contents of memory locations 0x1000 to 0x1003 are shown.

0x10000x10010x10020x1003Big-endian0x0A0xC00xFF0xEELittle-endian0xEE0xFF0xC00x0A Why Different Byte Ordering?

This is a difficult question. There is no logical reason why different microprocessor vendors decided to use different ordering schemes. Most of the reasons are historical. For example, Intel processors have traditionally been little-endian. Motorola processors have always been big-endian.

The situation is actually quite similar to that of Lilliputians in Gulliver's Travels. Lilliputians were divided into two groups based on the end from which the egg should be broken. The big-endians preferred to break their eggs from the larger end. The little-endians broke their eggs from the smaller end.

Conversion Routines

Routines to convert between big-endian and little-endian formats are actually quite straight forward. The routines shown below will convert from both ways, i.e. big-endian to little-endian and back.

Big-endian to Little-endian conversion and backshort convert_short(short in){ short out; char *p_in = (char *) ∈ char *p_out = (char *) &out; p_out[0] = p_in[1]; p_out[1] = p_in[0]; return out;}long convert_long(long in){ long out; char *p_in = (char *) ∈ char *p_out = (char *) &out; p_out[0] = p_in[3]; p_out[1] = p_in[2]; p_out[2] = p_in[1]; p_out[3] = p_in[0]; return out;}

粘贴源: http://www.eventhelix.com/RealtimeMantra/ByteAlignmentAndOrdering.htm

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有