• C#去除byte数组头尾杂质(即不需要的数据)


    代码如下:

            /// <summary>
            /// 去除byte数组头尾杂质(即不需要的数据)
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                //---------------------去除头杂质---------------------------------
                byte[] listTemp = new byte[] 
                {   
    				1, 2, 3, 4, 5, 6, 7, 8, 0x55, 0xaa, 6, 6, 6, 6, 6, 6, 6, 7, 7, 
                    7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,7,8,8,
                    1, 4, 3, 2, 4, 6, 7, 8, 9, 2, 1, 0x55, 0xaa, 1, 2, 3, 4, 6 ,2
                };
    
                int index = 0;
                while (true)
                {
                    if (listTemp[index] != 0x55 && listTemp[index++] != 0xaa)
                        index++;
                    else break;
                }
                byte[] listNew = new byte[listTemp.Length - index];
                Array.Copy(listTemp, index, listNew, 0, listTemp.Length - index);
    
                int count = 10;
                List<byte> finaly = new List<byte>();
                int lastStart = listNew.ToList<byte>().LastIndexOf(0x55);
                if (listNew[lastStart + 1] == 0xaa)
                {
                    if ((listNew.Length) - (lastStart + 1) != count)
                    {
                        byte[] listFinaly = new byte[lastStart];          //listFinaly 此处数组就是剔除了头尾杂质的
                        Array.Copy(listNew, 0, listFinaly, 0, lastStart);
                        finaly = listFinaly.ToList<byte>();
                    }
                }
                Console.ReadLine();
            }



  • 相关阅读:
    51 张图助你彻底掌握 HTTP
    Nginx从原理到实战
    vu3.0 + ts + swiper6 的问题
    使用 react-router-dom v5 查询query 参数的方法
    visual studio 2015配置SVN
    SVN使用教程总结
    C#与SAP进行数据交互
    shell csv/txt文件对比
    persto array_join(array_agg(),',')
    shell 拼接html table 发送邮件
  • 原文地址:https://www.cnblogs.com/myesn/p/5601601.html
Copyright © 2020-2023  润新知