美文网首页
C# 高低字节转换的问题

C# 高低字节转换的问题

作者: 天山海梦 | 来源:发表于2021-08-27 09:30 被阅读0次
        byte[] command = new byte[2];
        double test1 = 1234;
        UInt16 result = (UInt16)(test1);
        command[0] = (byte)(result >> 8);//高位
        command[1] = (byte)(result & 0xff);//低位
        Console.WriteLine("{0}", FormatBytes(command) );

将byte数组(长度2,高字节在前,低字节在后),转成double数据;

byte[] command2 = new byte[2] { 0x15, 0xee };
double result2 = command2[0] * 256 + command2[1];
Console.WriteLine("{0}", result2);

相关文章

网友评论

      本文标题:C# 高低字节转换的问题

      本文链接:https://www.haomeiwen.com/subject/lstmiltx.html