// b_add1.tm given a binary number on input tape, add 1 to that number // input must have leading 0 // The basic algorithm is to look backwards from input // if lowest bit, first in backwards scan is 0, set to 1, done // if 1 set to 0 and continue bacwards scan start s halt f trace all s 0 s ## R move right to end "#]" s 1 s ## R move right to end "#]" s #] a ## L found end, go to state a a 0 f 1 L done a 1 c 0 L add and carry c 0 f 1 L done c 1 c 0 L done if input has leading zero // c 1 d 0 L // c #[ f 1 R // d #[ f 1 R // d 0 f 1 L // d 1 d 0 L enddef tape 0 tape 01 tape 00 tape 011 tape 0101