After that, replace '1' with '0' and '0' with '1'.
Stop when you reach the beginning of the string.
Intuition:
Whenever a number's 1's complement is taken and 1 bit is added to its LSB (Least Significant Bit), all the 1's (which were originally 0) appearing together from right will add with the carry and change back to 0. Since the first encounter of 0 in 1's complement string (which was originally 1) , every '1' bit to its right, if any, will add 1 and change to 0. The first encountered 0 in the string will add 1 and change back to 1, as in the original string. This does not impact any further bit to its left, thus final string have
All 0's same to the right of first '1' bit encountered ( ( complement of 0) + 1) = 0 + carry(=1) to its left element)
The first '1' bit encountered will also revert back to 1 the same way.
All other bits to its left will be flipped without any restrictions.
States:
q0: Initial state
q1, q2: Transition states
qH: Final state
Symbols:
0, 1: Binary digits
B: Blank symbol
R, L: Right and left movements
Steps:
In state q0, move right until you encounter a BLANK symbol. Then, transition to state q1 and go to left.
In state q1, continue moving left until you encounter the first '1'. Transition to state q2.
In state q1, if BLANK symbol is encountered, then transition to state qH.
In state q2, replace '1' with '0' and '0' with '1'.
If BLANK symbol is encountered, then transition to state qH.