How can I create Turing Machine which w开发者_JS百科ill calculate sum of two binary digits separated by #, eg. 111#101B, where B is for blank? Result can be written at the end of the tape.
- Write a turing machine to convert both binary numbers to unary (maintaining the blank between them).
- Write a turing machine to replace the blank with a 1, and chop a digit off the end.
- Write a turing machine to convert a unary number to binary.
- Chain those three machines together.
assuming input a#(1)b convert to a#(1)b#(2)c#(3)BLANK
Blank will be filled with sum. Make 2 cases for LSB of 'a'. Further divide 2 cases for LSB of 'b'. 'c' is the carry bit that is initially 0. Make seperate 2 cases for each of the four cases and update the carry bit on the way. Path is chosen based on if 'c' was 0 or 1.
Picture shows a rough sketch.
Final result will be reversed value of original sum. You reverse this again. Take the pic with a grain of salt. It is just a rough sketch. Nomenclature is not followed.
精彩评论