字节序类型 [英] Types of endianness

查看:120
本文介绍了字节序类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下类型的字节序有什么区别?

What is the difference between the following types of endianness?


  • 字节(8b)不变的字节序

  • 半字(16b)不变的大和小字节序

  • 字(32b)不变的大小似的小字节

  • double-单词(64b)不变的大小字节序

  • byte (8b) invariant big and little endianness
  • half-word (16b) invariant big and little endianness
  • word (32b) invariant big and little endianness
  • double-word (64b) invariant big and little endianness

还有其他类型/变量吗?

Are there other types/variations?

推荐答案

尾数映射有两种方法:地址不变性数据不变性

There are two approaches to endian mapping: address invariance and data invariance.

在这种类型的映射中,字节的地址始终保留在大小之间。这具有颠倒特定数据(例如2或4字节字)的有效顺序(最高有效到最低有效)的副作用,并因此反转了数据的解释。具体而言,在小字节序中,数据的解释对最重要的字节是最低有效的,而在大字节序中,数据的解释对于最不重要的字节是最重要的。在这两种情况下,访问的字节集保持不变。

In this type of mapping, the address of bytes is always preserved between big and little. This has the side effect of reversing the order of significance (most significant to least significant) of a particular datum (e.g. 2 or 4 byte word) and therefore the interpretation of data. Specifically, in little-endian, the interpretation of data is least-significant to most-significant bytes whilst in big-endian, the interpretation is most-significant to least-significant. In both cases, the set of bytes accessed remains the same.

示例

地址不变性(也称为字节不变性):字节地址不变,但字节的重要性相反。

Address invariance (also known as byte invariance): the byte address is constant but byte significance is reversed.

Addr   Memory
       7    0
       |    |    (LE)   (BE)
       |----|
 +0    | aa |    lsb    msb
       |----|
 +1    | bb |     :      :
       |----|
 +2    | cc |     :      :
       |----|
 +3    | dd |    msb    lsb
       |----|
       |    |

At Addr=0:          Little-endian          Big-endian
Read 1 byte:              0xaa                0xaa   (preserved)
Read 2 bytes:           0xbbaa              0xaabb
Read 4 bytes:       0xddccbbaa          0xaabbccdd



数据不变性



在此映射类型时,将保留特定大小数据的相对字节有效值。因此,对于不同的数据大小,存在不同类型的数据不变字节序映射。例如,将32位字不变字节序映射用于数据大小为32的情况。保留特定大小的数据值的效果是,在大小字节序和小字节序映射之间,数据中字节的字节地址是相反的。

Data Invariance

In this type of mapping, the relative byte significance is preserved for datum of a particular size. There are therefore different types of data invariant endian mappings for different datum sizes. For example, a 32-bit word invariant endian mapping would be used for a datum size of 32. The effect of preserving the value of particular sized datum, is that the byte addresses of bytes within the datum are reversed between big and little endian mappings.

示例

32位数据不变性(也称为单词不变性):数据是一个32位单词,其值始终为 0xddccbbaa ,与字节序无关。但是,对于小于一个字的访问,字节的地址在大小端映射之间反转。

32-bit data invariance (also known as word invariance): The datum is a 32-bit word which always has the value 0xddccbbaa, independent of endianness. However, for accesses smaller than a word, the address of the bytes are reversed between big and little endian mappings.

Addr                Memory

            | +3   +2   +1   +0 |  <- LE
            |-------------------|
+0      msb | dd | cc | bb | aa |  lsb
            |-------------------|
+4      msb | 99 | 88 | 77 | 66 |  lsb
            |-------------------|
     BE ->  | +0   +1   +2   +3 |


At Addr=0:             Little-endian              Big-endian
Read 1 byte:                 0xaa                    0xdd
Read 2 bytes:              0xbbaa                  0xddcc
Read 4 bytes:          0xddccbbaa              0xddccbbaa   (preserved)
Read 8 bytes:  0x99887766ddccbbaa      0x99887766ddccbbaa   (preserved)

示例

16位数据不变性(也称为半字不变性):数据为16位
的值始终为 0xbbaa ,与字节序无关。但是,对于小于半个字的访问,字节的地址在大小端映射和大小端映射之间反转。

16-bit data invariance (also known as half-word invariance): The datum is a 16-bit which always has the value 0xbbaa, independent of endianness. However, for accesses smaller than a half-word, the address of the bytes are reversed between big and little endian mappings.

Addr           Memory

            | +1   +0 |  <- LE
            |---------|
+0      msb | bb | aa |  lsb
            |---------|
+2      msb | dd | cc |  lsb
            |---------|
+4      msb | 77 | 66 |  lsb
            |---------|
+6      msb | 99 | 88 |  lsb
            |---------|
     BE ->  | +0   +1 |


At Addr=0:             Little-endian              Big-endian
Read 1 byte:                 0xaa                    0xbb
Read 2 bytes:              0xbbaa                  0xbbaa   (preserved)
Read 4 bytes:          0xddccbbaa              0xddccbbaa   (preserved)
Read 8 bytes:  0x99887766ddccbbaa      0x99887766ddccbbaa   (preserved)

示例

64位数据不变性(也称为双字不变):数据是一个64位
字,始终具有 0x99887766ddccbbaa 值,与字节顺序无关。但是,对于小于双字的访问,字节的地址在大尾数映射和小尾数映射之间反转。

64-bit data invariance (also known as double-word invariance): The datum is a 64-bit word which always has the value 0x99887766ddccbbaa, independent of endianness. However, for accesses smaller than a double-word, the address of the bytes are reversed between big and little endian mappings.

Addr                         Memory

            | +7   +6   +5   +4   +3   +2   +1   +0 |  <- LE
            |---------------------------------------|
+0      msb | 99 | 88 | 77 | 66 | dd | cc | bb | aa |  lsb
            |---------------------------------------|
     BE ->  | +0   +1   +2   +3   +4   +5   +6   +7 |


At Addr=0:             Little-endian              Big-endian
Read 1 byte:                 0xaa                    0x99
Read 2 bytes:              0xbbaa                  0x9988
Read 4 bytes:          0xddccbbaa              0x99887766
Read 8 bytes:  0x99887766ddccbbaa      0x99887766ddccbbaa   (preserved)

这篇关于字节序类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆