标签:存储 else console mouse com main alt blog sel
static void Main(string[] args)
{
uint value = 0x12345678;
Console.WriteLine("原始字节序:0x12345678");
byte[] bigLittleEndian = BitConverter.GetBytes(value); //得到小端字节序数组
//低地址存高位为大端序
if (bigLittleEndian[0] == 0x12)
{
Console.WriteLine("C#在Windows中是大端序存储");
}
//低地址存低位为小端序
else if (bigLittleEndian[0] == 0x78)
{
Console.WriteLine("C#在Windows中小端序存储");
}
Console.WriteLine("小端字节序:"+BitConverter.ToString(bigLittleEndian)+ "低地址存低字节");
Array.Reverse(bigLittleEndian); //反小端序数组转成大端。
Console.WriteLine("大端字节序:" + BitConverter.ToString(bigLittleEndian)+ "低地址存高字节");
}
运行结果
而modbus中的Data的是大端序,即低地址存高字节符合网络标准字节序。
标签:存储 else console mouse com main alt blog sel
原文地址:https://www.cnblogs.com/JerryMouseLi/p/13997445.html