The last step, we multiply 4 with our position in M, to obtain the value 20, and then remainder it against the bit count of S, obtaining 2. We thereby flip the 2nd bit in S, thus S becomes "000".

Should read:

The last step, we multiply 4 with our position in M, to obtain the value 20, and then remainder it against the bit count of S, obtaining 2. We thereby flip the 2nd bit in S, thus S becomes "011".

"2nd bit" being in the last position, as we zero-index (0th, 1st, 2nd).

And...

The last step, we multiply 3 with our position in M, to obtain the value 15, and then remainder it against the bit count of R, obtaining 1. We thereby flip the 1st bit in R, thus R becomes "1001".

Should read:

The last step, we multiply 3 with our position in M, to obtain the value 15, and then remainder it against the bit count of R, obtaining 3. We thereby flip the 3rd bit in R, thus R becomes "1100".

As the bit-count of R is four; 15 mod 4 returns 3.

]]>The second step, we multiply 2 with our position in M, to obtain the value 10, and then remainder it against the bit count of S, obtaining 1.

should in fact read

The second step, we multiply 2 with our position in M, to obtain the value 10, and then remainder it against the bit count of S, obtaining 2.

and that the rest of the operations are incorrect from there on ?

I'd say this is not the case, the bitcount of S is 3, and 10 % 3 = 1.

If you actually mean something else please give explicit difs, it's rather impossible to guess-follow otherwise.

]]>