int Len = BitConverter.ToInt32(mNetRecvStream, rIdx); 改成读大端序

动态 未结 0 81
小小草
小小草 LV1 2023年9月23日 23:40 发表
你可以将代码修改为以下形式,使用大端序读取长度: ``` byte[] lenBytes = new byte[4]; Array.Copy(mNetRecvStream, rIdx, lenBytes, 0, 4); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); } int Len = BitConverter.ToInt32(lenBytes, 0); ``` 这里先将 mNetRecvStream 中的四个字节复制到 lenBytes 数组中,然后判断当前系统是否为小端序,如果是,则使用 Array.Reverse 方法将 lenBytes 数组反转,使其变成大端序。最后使用 BitConverter.ToInt32 方法将 lenBytes 数组转换为 int 类型的数据 Len。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复