C# 高低字节转换的问题

2021-08-27  本文已影响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);

上一篇 下一篇

猜你喜欢

热点阅读