有关Endian-ness和.Net的详细信息? [英] Details about Endian-ness and .Net?

查看:93
本文介绍了有关Endian-ness和.Net的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些关于字节序的问题,它们之间的关联性很强,以至于我保证将它们作为一个问题加以解决:

I have a few questions about endian-ness that are related enough that I warrant putting them in as one question:

1)字节序是否由决定。是网络还是硬件?

1) Is endian-ness decided by .Net or by the hardware?

2)如果是由硬件决定的,我如何找出C#中硬件的字节顺序?

2) If it's decided by the hardware, how can I figure out what endian the hardware is in C#?

3)字节序是否会影响二进制交互,例如OR,AND,XOR或移位?即会一次向右移动是否总是会移出最低有效位吗?

3) Does endian-ness affect binary interactions such as ORs, ANDs, XORs, or shifts? I.E. Will shifting once to the right always shift off the least significant bit?

4)我对此表示怀疑,但是从不同版本的字节序开始,字节序是否有所不同?网络框架?我认为它们都是一样的,但是我学会了停止假设一些诸如此类的较低级别的细节。

4) I doubt it, but is there a difference in endian-ness from different versions of the .Net framework? I assume they're all the same, but I've learned to stop assuming about some of the lower level details such as this.

如果需要,我可以问一下这些是不同的问题,但是我认为知道这些问题之一的人可能都知道所有问题的答案(或者可以为我指出正确的方向)。

If need be, I can ask these as different questions, but I figure anybody who knows the answer to one of these probably knows the answer to all of them (or can point me in a good direction).

推荐答案

1)硬件。

2) BitConverter.IsLittleEndian

3)字节序不影响按位运算。向右移动是在最低有效位方向上移动。 来自Oops评论的更新:但是,字节序确实会影响二进制输入和输出。在读取或写入大于字节的值时(例如,从 BinaryReader 读取 int 或使用 BitConverter ),则必须考虑字节顺序。一旦正确读入值,则所有按位操作都将正常工作。

3) Endianness does not affect bitwise operations. Shifting to the right is shifting in the least-significant-bit direction. UPDATE from Oops' comment: However, endianness does affect binary input and output. When reading or writing values larger than a byte (e.g., reading an int from a BinaryReader or using BitConverter), you do have to account for endianness. Once the values are read in correctly, then all bitwise operations act as normal.

4).NET的大多数版本都是小端的。值得注意的例外包括XBox和Mono或Compact Framework支持的某些平台。

4) Most versions of .NET are little endian. Notable exceptions include the XBox and some platforms supported by Mono or the Compact Framework.

这篇关于有关Endian-ness和.Net的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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