把一个byte[10],两两合并成原数组的一半

把一个byte[10],两两合并成原数组的一半

byte[] a=new byte[10];
byte[] b=new byte[5];

a两两合并后

a[0]=10;
a[1]=10;

b[0]=1010;
    int[] UnionByteArr(byte[] byteArr)
    {
        byte[] fixedByteArr = new byte[byteArr.Length + byteArr.Length % 2];//修正后的byte数组,确保数组长度为偶数
        Array.Copy(byteArr, fixedByteArr, byteArr.Length);//将原数组的值拷贝到修正后的数组
        int[] unionArr = new int[fixedByteArr.Length / 2];//创建两两合并后的数组,注意要创建为int类型,因为byte类型范围[0,255],所以组后范围为[0,255255]
        for (int i = 0; i < unionArr.Length; i++)
        {
            unionArr[i] = (int)(fixedByteArr[2 * i] * Math.Pow(10, fixedByteArr[2 * i + 1].ToString().Length) + fixedByteArr[2 * i + 1]);//进行合并
        }
        return unionArr;
    }

描述太模糊了,没看懂题意

照你所说就很简单了

                    byte[] a = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
        List<byte> list = new List<byte>();
        for (int i = 0; i < a.Length; i += 2)
        {
            byte c = byte.Parse($"{a[i]}{a[i + 1]}");
            list.Add(c);
        }
        byte[] b = list.ToArray();