Here's pseudo-code for a possibility. It assumes that the arrays begin with index 0 so it will need to be adjusted if you use index one (I'm a C programmer). It assumes that you have to do all the elements at one pass. It assumes that you are using structured text . It assumes that the result array is not allowed to go through temporary values during the execution of the pass.
Bits_In - ARRAY [0..127] of BOOL
Word_Out - ARRAY[0..7] OF WORD
Temp_Words - ARRAY[0..7] OF WORD
UINT Word_Loop, Bit_Loop;
WORD Or_Mask
(* Zero out the temporary array *)
FOR Word_Loop:= 0 to 7 BY 1 DO
Temp_Words[Word_Loop] = 0;
FOR Bit_Loop := 0 to 15 BY 1 DO
IF Bits_In[Word_Loop * 16 + Bit_Loop] == TRUE THEN
Or_Mask := 1;
IF Bit_Loop > 0 THEN
shift Or_Mask left Bit_Loop bits
END_IF;
Temp_Words[Word_Loop] := Temp_Words[Word_Loop] OR OR_Mask;
END_IF;
END_FOR;
Word_Out[Word_Loop] = Temp_Words[Word_Loop];
END_FOR;
You have to make sure the compiler uses a bitwise (not a logical) OR when you use the OR_Mask to turn the bit on.
This quickly given answer is not ready to go - it needs some research to be Schneider-specific. One advantage of it is that the method is mostly processor-independent so it can be easily modified for any CPU.
Eliminating the temporary buffer would give a little more speed. If the shift mechanism is guaranteed to behave itself with a count of zero the extra IF could be eliminated.