0

What is the most efficient (fastest) way to serialize / transpose data in this somewhat odd way. Let's say I have 8 array with some data in them.

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

Basically Bit0 of the output Array contains serialized data of the input Array0. Bit1 of the output Array contains serialized data of the input Array1 etc...

I'm using a microchip PIC32 device but that shouldn't matter too much, it is still standard C

Borisw37
  • 739
  • 2
  • 7
  • 30
  • for clarity, did you intend for **all** bits in any given single Output octet to be either lit or clear? Your sample suggests this, but its seems a little foggy in your description. – WhozCraig Oct 20 '14 at 20:21
  • Yes, if I understood you correctly. Byte0 of the output will contain Byte0.Bit0 of all 8 input arrays. Byte1 of the output will contain Byte0.Bit1 of all 8 input arrays. And so on.. Byte 8 of the output will contain Byte1.Bit0 of all 8 input arrays. Does this make sense? – Borisw37 Oct 20 '14 at 20:41

1 Answers1

0

I don't see why would you need to do such thing but you can do it using the shift operator.

You would need to create a matrix for those Arrays:

char Array[N][M]

And do it like this:

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 should be 8, and 8 only.