| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2229 人关注过本帖
标题:计算机内存对数据的存储顺序?
只看楼主 加入收藏
olivezhang
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-9-14
收藏
 问题点数:0 回复次数:15 
计算机内存对数据的存储顺序?
计算机系统对数据的存储顺序是怎样的?如:十六进制数0xABCD,是先存储低位0xAB, 后存储高位 0xCD, 还是反过来呢?感觉大部分计算机是先低位后高位的,对吧?
搜索更多相关主题的帖子: 计算机内存 计算机系统 数据 顺序 低位 
2006-03-03 15:49
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
收藏
得分:0 
我认为是同时储存。。。

for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 01:14
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
这是BigEndian 和 LittleEndian的问题, 你看看计算机结构方面的书就知道了,如果你写的是本地机器上的应用程序, 那么Byte的先后次序你是不用去关心的. 不过如果你的程序是与网络有关,那么你需要遵守一些原则, 关于这个话题,我不做展开讨论了,自己去看书吧.

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-03-04 03:34
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
收藏
得分:0 
以下是引用kai在2006-3-4 3:34:00的发言:
那么Byte的先后次序你是不用去关心的.
你说的是 bit 吧

for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 13:23
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
DarkHero,
看来你不清楚我在说什么啊, 要详细说, 比较累, 你还是找本计算机结构方面的书吧, 或者你上网找找Bigendian 和 Littleendian 的概念吧。

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-03-04 14:41
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 

For program objects that span multiple bytes, we must establish two
conventions: what will be the address of the object, and how will we
order the bytes in memory. In virtually all machines, a multibyte object
is stored as a contiguous sequence of bytes, with the address of the
object given by the smallest address of the bytes used. For example,
suppose a variable x of type int has address 0x100, that is, the value
of the address expression &x is 0x100. Then the four bytes of x would
be stored in memory locations 0x100, 0x101, 0x102, and 0x103.


For ordering the bytes representing an object, there are two common
conventions. Consider a w-bit integer having a bit representation
[xw-1,xw-2,......,x1,x0], where xw-1 is the most significant bit, and x0 is
the least. Assuming w is a multiple of eight, these bits can be grouped
as bytes, with the most significant byte having bits [xw-1,xw-2,......,xw-8],
the least significant byte having bits [x7, x6,......,x0], and the other bytes
having bits from the middle. Some machines choose to store the object
in memory ordered from least significant byte to most, while other machines
store them from most to least. The former convention—where the least
significant byte comes first—is referred to as little endian. This convention
is followed by most machines from the former Digital Equipment Corporation
(now part of Compaq Corporation), as well as by Intel. The latter convention
—where the most significant byte comes first—is referred to as big endian.
This convention is followed by most machines from IBM, Motorola, and
Sun Microsystems. Note that we said “most.” The conventions do not
split precisely along corporate boundaries. For example, personal computers
manufactured by IBM use Intel-compatible processors and hence are little
endian. Many microprocessor chips, including Alpha and the PowerPC by
Motorola can be run in either mode, with the byte ordering convention
determined when the chip is powered up.

Continuing our earlier example, suppose the variable x of type int and
at address 0x100 has a hexadecimal value of 0x01234567. The ordering
of the bytes within the address range 0x100 through 0x103 depends on
the type of machine:

Big endian
0x100 0x101 0x102 0x103
01 23 45 67
Little endian
0x100 0x101 0x102 0x103
67 45 23 01

Note that in the word 0x01234567 the high-order byte has hexadecimal
value 0x01, while the low-order byte has value 0x67.

People get surprisingly emotional about which byte ordering is the proper
one. In fact, the terms “little endian” and “big endian” come from the
book Gulliver’s Travels by Jonathan Swift, where two warring factions could
not agree by which end a soft-boiled egg should be opened—the little end
or the big. Just like the egg issue, there is no technological reason to choose
one byte ordering convention over the other, and hence the arguments
degenerate into bickering about sociopolitical issues. As long as one of
the conventions is selected and adhered to consistently, the choice is arbitrary.

For most application programmers, the byte orderings used by their machines
are totally invisible. Programs compiled for either class of machine give identical
results. At times, however, byte ordering becomes an issue. The first is when
binary data is communicated over a network between different machines.
A common problem is for data produced by a little-endian machine to be sent
to a big-endian machine, or vice-versa, leading to the bytes within the words
being in reverse order for the receiving program. To avoid such problems,
code written for networking applications must follow established conventions
for byte ordering to make sure the sending machine converts its internal
representation to the network standard, while the receiving machine converts
the network standard to its internal representation.

能看懂,翻不出来.

[此贴子已经被作者于2006-3-4 16:27:11编辑过]


2006-03-04 15:36
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
收藏
得分:0 

小译了一下,不正之处请多多包涵。。。
正文:
对于程序中的那些需要占据多个字节(下面就保留 byte ,还有 muiltibyte 这样较明显)的对象,我们必须对他们作出一些约定:1、对象的地址是什么? 2、构成该对象的 bytes 在内存中又是按照何种顺序排列的呢?
实际上在大多数的计算机里,muiltibyte(占据内存多个字节) 的对象在内存中是按照连续的byte排列的,对象的地址就是这些byte中的最小的那个byte(注:因为在内存中是给每个byte分配一个独立的地址的)的地址。举个例子:int x;(注:现在大多数计算机int是占4个byte),如果对象x的地址为Ox100,即 &x==Ox100,那么x在内存中的bytes的地址将依次为0x100, 0x101, 0x102, 和 0x103。

既然有序的byte可以表示一个对象,那么通常也就有2种约定(其实还有种middle-endian):例如一个w-位的整数:[xw-1,xw-2,......,x1,x0], 其中xw-1 是最大位,x0 是最小位。假设w是8的倍数,那么该整数可以被分为多个byte,最大byte由[xw-1,xw-2,......,xw-8]构成, 而最小byte由[x7, x6,......,x0]构成,其他的byte就介于两者之间。 有些计算机选择 最小byte到最大byte 的约定来储存,而其他的计算机则采用相反的约定。
前者的被称为:little-endian,这种机制被Digital Equipment Corporation公司(现已并入Compaq)以及Intel的大多数计算机所采用;后者被称为:big-endian,被IBM, Motorola, and Sun Microsystems的大多数计算机所采用。
注意这里说的是“大多数”,因为这些约定并没有给公司“分界”。比如IBM生产的个人电脑由于使用了Intel兼容的微处理器,就采用了 little-endian 机制。许多微处理器芯片,比如Alpha 和 Motorola的PowerPC可以兼容这两种模式,只有当芯片被power up(供电???)时才确定使用哪种模式。
-----------------------------------------------
底下的有点罗嗦了,我大概说一下:
比如一个int:假设地址为Ox100,值为:Ox01234567(十六进制),那么最大byte:Ox01,最小byte:Ox67(根据前文显而易见)。
那么显然:
Big endian(从最大byte到最小byte)
0x100 0x101 0x102 0x103
01 23 45 67
Little endian(从最小byte到最大byte)
0x100 0x101 0x102 0x103
67 45 23 01.

下面讲了“little endian” and “big endian”名字的由来…………………………最后得出结论,没有孰优孰劣之分,只要选个做标准,就是好的。

这2种约定对于我们一般的程序员(主要是写应用程序的)没什么影响。但有时候,比如网络编程,计算机A与计算机B通信时麻烦就来了,假如A用little-endian ,而B用big-endian,显然数据就差大了……那么如何解决呢?可以A采用它的内部机制,而到网络上转换成一种网络标准,到B上再从网络标准换成B的机制,这样就OK了。


for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 16:48
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
收藏
得分:0 
第二次翻译呀(第一次是大1时翻译英文课本的几页,翻译好老师总结给下一届用的……),呼呼

for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 16:50
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
收藏
得分:0 



2006-03-04 19:13
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
收藏
得分:0 
笑什么……

for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 20:30
快速回复:计算机内存对数据的存储顺序?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064086 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved