C# Byte数组与Int16数组之间的转换(转)

您所在的位置:网站首页 byte转成int C# Byte数组与Int16数组之间的转换(转)

C# Byte数组与Int16数组之间的转换(转)

2023-12-08 00:17| 来源: 网络整理| 查看: 265

u

这里提供两个函数,完成相互转换。

        private void Int16ToByte(Int16[] arrInt16, int nInt16Count, ref Byte[] destByteArr)        {            //高字节放在前面,低字节放在后面            for (int i = 0; i < nInt16Count; i++ )            {                destByteArr[2 * i + 0] = Convert.ToByte((arrInt16[i] & 0xFF00) >> 8);                destByteArr[2 * i + 1] = Convert.ToByte((arrInt16[i] & 0x00FF));            }        }

        private void ByteToInt16(Byte[] arrByte, int nByteCount, ref Int16[] destInt16Arr)        {            //按两个字节一个整数解析,前一字节当做整数高位,后一字节当做整数低位            for (int i = 0; i < nByteCount / 2; i++)            {                destInt16Arr[i] = Convert.ToInt16(arrByte[2 * i + 0]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3