Suppose I've two bit strings: runs
and toggler
, where a run is a group of contiguous like bits. Both of these bit strings can have an arbitrary arrangement of 1s and 0s (on and off respectively). For the sake of the question, I will use the example values below:
runs : 1111011010100011
toggler: 1010001010010110
Does there exist a way to mask the two bit strings, or otherwise utilise any features of c++ outside of iteration (though the more general / language-independent, the better), to produce a result
bit string that contains every run of 1s in runs
which possesses at least one bit who has a corresponding 1 in toggler
?
A worked example of this using the example values provided can be seen as follows:
runs : 1111011010100011
toggler: 1010001010010110
result : 1111011010000011
Where the first, second, third, and fourth runs of 1s in runs
all possess at least one 1 corresponding to their constituent bits in toggler
.
So far, I have that it is apparent that the positions of some of result
's 0s can be identified, being the bits corresponding to ~runs
. It is also apparent that the positions of some of result
's 1s can be identified as runs & toggler
. Given this information, any remaining unknown bits (equivalent to the bits that satisfy the condition runs & ~toggler
) can be determined to be 0 iff the bits at either end of that run of unknown bits are zero. This can once again be seen below in the bit string unknown
:
runs : 1111011010100011
toggler: 1010001010010110
unknown: 1_1_0_1010_0001_ // 1 = runs & toggler, 0 = ~runs, _(unknown) = runs & ~toggler
result : 1111011010000011