0

このやや奇妙な方法でデータをシリアル化/転置する最も効率的な (最速の) 方法は何ですか。いくつかのデータを含む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

基本的に、出力配列のビット 0 には、入力配列 0 のシリアル化されたデータが含まれます。出力配列のビット 1 には、入力配列 1 などのシリアル化されたデータが含まれます。

私はマイクロチップの PIC32 デバイスを使用していますが、それはそれほど重要ではありません。標準 C のままです。

4

1 に答える 1

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 のみです。

于 2014-10-20T20:57:56.887 に答える