C# modbus RTU 中使用到的 ushort[] 转 int 与 int 转 ushort[]

        public static int ushorts2int(ushort[] res)
        {
            int high = res[0];
            int low = res[1];
            int value = (high << 16) + low;
            return value;
        }

        public static ushort[] int2ushorts(int res)
        {
            ushort ust1 = (ushort)(res >> 16);
            ushort ust2 = (ushort)res;
            return new ushort[] { ust1, ust2 };
        }

 

posted @ 2023-08-02 13:00  威流  阅读(455)  评论(0编辑  收藏  举报