C#中BitConverter.ToInt32的用法

请问字节顺序应如何排列?大端还是小端?
例如:
我希望得到转换出来的数是:0afd89d1
temp[0] = 0x0a;
temp[1] = 0xfd;
temp[2] = 0x89;
temp[3] = 0xd1;
result = BitConverter.ToInt32(temp, 0);
按我的语句能转换出来0afd89d1吗?

不能!按你的temp数组,转换的结果是d189fd0a

改成这样的

    class Program
    {
        static void Main(string[] args)
        {
            byte[] temp = { 0xd1, 0x89, 0xfd,  0x0a};
            int result = BitConverter.ToInt32(temp, 0);
            Console.WriteLine("{0:x8}", result);
        }

输出结果是0afd89d1

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-04
Array.Reverse(temp, 0, 4);
var result = BitConverter.ToInt32(temp, 0);
第2个回答  2014-03-04
不行要反序
byte[] temp = new byte[4];
temp[3] = 0x0a;
temp[2] = 0xfd;
temp[1] = 0x89;
temp[0] = 0xd1;
var result = BitConverter.ToInt32(temp, 0);本回答被提问者采纳