> I have an Array of 0s and 1s (00111010001111). I need to calculate
> how many ones occure in a row eliminating 0s and placing the sums in a
> new array for example
> (01001100111001111)= (1 2 3 4)
Build a small state machine with the initial state and two working
states based upon the last item received. Each state has two
transitions based upon the current character. It might be easiest to
label them 00, 01, 10, and 11. You should add two shift register
elements to the array, one is the current count of consecutive 1's seen.
The other shift register is the array of counts already seen. The
array should be initialized to empty, and the count to zero. The
actions to take for each transition are listed below.
00 Stay in state 0. Leave the
count and the array alone.
01 Initialize the count to one and transition to state 1.
10 Add the count to the array, zero count, and go to state 0.
11 Stay in state 1, increment the count, leave the array alone.
After seeing the last character, put any nonzero count in the array as well.
There are other approaches you could take like searching for 1, then for
zero ... and breaking the array up into lots of smaller arrays, then
doing another loop counting array sizes. This will probably look
simpler, but will take more time and memory to execute.
Greg McKaskle