数组值如何存储在Little Endian与Big Endian体系结构中 [英] How are array values stored in Little Endian vs. Big Endian architecture

查看:114
本文介绍了数组值如何存储在Little Endian与Big Endian体系结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在询问如何分辨数组中的一个元素何时结束,而另一个元素是在端序体系中开始的。

I am inquiring about how to tell when one element in an array has finished and another is beginning in an endian architecture.

我有2个数组,它们的大小为long为8,char的大小为1

I have 2 arrays where the size of long is 8 and the size of char is 1

long x [2] = {0x012345,0xFEDC};

char c [12] = {'a','b','c','d','e','f ','g','h','0','1','2','3'};

我想知道如果我们考虑x从内存地址 0x100 开始,而c从内存地址 0x200 <开始,这些值将如何存储在不同的Endian体系结构中? / code>。

And I was wondering how these values would be stored in the different Endian architectures if we consider x starting at memory address 0x100 and c starting at memory address 0x200.

我认为Big Endian地址为 {01,23,45,FE,DC} ,其中集合的第一个元素位于内存地址 0x100 ,第二个元素是 0x101 ,第三个是 0x102 ,依此类推,因为它存储的值基于MSB在前。但是,我不确定在表示内存中数组的值之间是否应该有一个指示符来表明它是一个不同的元素,例如null char。像 {01,23,45,'\0',FE,DC}

I thought that the Big Endian address would be {01,23,45,FE,DC} where the first element of the set is at memory address 0x100, the next is 0x101, third is 0x102, and so on since it stores the values based on the MSB being first. However, I'm not sure if there is supposed to an indicator between values that represent an array in memory to show that it's a different element, like a null char. like {01, 23, 45,'\0', FE, DC}

像小孩子一样我认为Endian Architecture会将其存储为 {45,23,01,DC,FE} ,但是我不确定是否应该有一些指标来突出显示不同的元素在数组中

Likewise for the Little Endian Architecture I believe it would store it as {45,23,01,DC,FE}, but I am not sure whether there should be some indicator to highlight the different elements in the array

推荐答案

在little-endian中,字节的存储顺序对最低有效位最低。大端则相反。例如, short x = 0x1234 将存储为 0x34 0x12

In little-endian, the bytes are stored in the order least significant to most signficant. Big-endian is the opposite. For instance, short x=0x1234 would be stored as 0x34,0x12 in little-endian.

如前所述,它只影响变量字节的顺序,而不影响每个字节中位的顺序。同样,C数组元素的顺序不受字节序的影响。 array [1] 总是在 array [0] <之后开始一个 sizeof(* array) / code>。

As already mentioned, it only affects the order of the bytes of a variable, and not the order of bits inside each byte. Likewise, the order of the elements of a C array are unaffected by endianness. array[1] always starts one sizeof(*array) after array[0].


但是,我不确定在
值之间是否应该有一个指标表示内存中的数组以表明它是一个不同的
元素,例如null char。

However, I'm not sure if there is supposed to an indicator between values that represent an array in memory to show that it's a different element, like a null char.

没有这样的指示符。


{01,23,45,FE,DC}

{01,23,45,FE,DC}

{ 45,23,01,DC,FE}

{45,23,01,DC,FE}

实际上是

{00,00,00,00,00,01,23,45,00,00,00,00,00,00,FE,DC}

{45,23,01,00,00,00,00,00, 00,DC,FE,00,00,00,00,00,00,00}

因为占用8个字节。

这篇关于数组值如何存储在Little Endian与Big Endian体系结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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