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 @   搬砖的L先生  阅读(68)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示