用C语言序列化/转置数据(PIC 32)

时间:2014-10-20 20:07:10

标签: c arrays pic pic32

以这种奇怪的方式序列化/转置数据的最有效(最快)方法是什么。 我们假设我有8个数组,其中包含一些数据。

char Array0[10];
char Array1[10];
.............
char Array7[10];

I need to get an output array that will have:
Output[80];
Output.byte0.bit0 = Array0.byte0.bit0
Output.byte0.bit1 = Array1.byte0.bit0
Output.byte0.bit2 = Array2.byte0.bit0
Output.byte0.bit3 = Array3.byte0.bit0
.....................................
Output.byte0.bit7 = Array7.byte0.bit0

Output.byte1.bit0 = Array0.byte0.bit1
Output.byte1.bit1 = Array1.byte0.bit1
Output.byte1.bit2 = Array2.byte0.bit1
Output.byte1.bit3 = Array3.byte0.bit1
.....................................
Output.byte1.bit7 = Array7.byte0.bit1

输出数组的Bit0基本上包含输入Array0的序列化数据。 输出Array的Bit1包含输入Array1的序列化数据 等...

我使用的是微芯片PIC32器件,但这不应该太重要,它仍然是标准的C

1 个答案:

答案 0 :(得分:0)

我不明白为什么你需要做这样的事情,但你可以使用移位运算符来做。

您需要为这些阵列创建一个矩阵:

char Array[N][M]

这样做:

int i=0;
for ( int e = 0 ;  e < M ; e++ )  //~ e for element number
    for (int m = 0 ; m < 8 ; m++ )  //~ m for mask 
    {
        char aux=0;
        for (int a = 0 ; a < N ; a++ ) //~ a for array
        {
            char temp = Array[a][e] & (0x01 << m );
            temp >>= m;
            temp <<= a;
            aux |= temp;
        }
        output[i++]= aux;
    }

N应为8和8。

相关问题