The tape head points to the beginning of the input string. Somehow, the TM has to know where the end of the string is. Different books define this differently, but it boils down the set of valid input strings being a "Prefix Set." (Which is more like a prefix-free set.) No string in the set of valid inputs is allowed to the be the prefix of another string in the input. So, if "12345" is a valid string, "123" is not allowed to be because "123" is prefix of "12345". Prefix: first part of a string. There are two really popular ways to have prefix sets. 1. Make sure every string is the same length as every other. (Fixed-length). So, five-digits numbers. Every five-digit numbers works, because no five-digit number is a prefix of any other. The TM would read five digits and know that it is done. "00000" "00001" "00002" "00003" "00004" ...etc, but not "000" or "0000". 2. The other common way is to have "delimiter." A "delimiter" is a character or string of characters that specifically indicates the end of a string. Obviously, the character cannot appear within the string itself. In command prompts, commands are delimited by ASCII 10 in Linux and modern Macs, by ASCII 13 in classic Macs (and old Apples) and by the strange ASCII 13-10 combination on Windows machines. On old teletypes, 13 was the carriage return, it moved the print head to the beginning of the line. And 10 was the line feed. It advanced the paper one line. So, to do both, required the 13-10 combination...and Windows still does this even though no one uses teletypes anymore. 13-10 is a "delimiter" for the Windows Command Prompt. In Old C, ASCII 0 was the delimiter for a string. All strings ended with ASCII 0 '\0'. Thus this character could not appear in a string. (However, it can in C++ or Java.) On a TM, most people use a space as a delimiter. However, sometimes liberties are taken with this, and this is fine so long as the set of valid inputs remains a prefix set. For example, an addition program might say the valid input is NUMBERNUMBER. And then the numbers are added. The is not a true delimiter since it appears in the middle of the input. But it's still perfectly clear where the input ends: the second space. Or you might have a TM that adds a whole row of numbers. This is fine as long as there is a clear way for the TM to tell when the row of numbers ends: Perhaps you use one space to separate the numbers in the list and put two spaces at the end. Similarly, the output of the program begins at the tape head, and ends where some predetermined technique tells you it ends. (Delimited by a space, for example.) Finite Automata and PDA have only two possible outputs: ACCEPT and NOT ACCEPT. TM's have a much more diverse output, but, of course, you can use a TM as a decision machine by restricting its output to "1" (accept) or "0" meaning not accept. If you can program a real computer using a real language to do something, you can also program a Turing Machine to do the same thing. You want to accept only prime numbers? For a TM, no problem! A simple TM program: Given a base 10 number delimited by space, multiply that number by 10. First of all, what's on the tape other than the input? Most books say you can assume the tape is blank except for your input. But even without that assumption, the TM is equally powerful. 0: '0',L,1 <==Moving left '1',L,1 '2',L,1 '3',L,1 '4',L,1 '5',L,1 '6',L,1 '7',L,1 '8',L,1 '9',L,1 ' ',L,1 1: '0',' ',2 <==Writing a space to the left of my number same for '1'-'9' and ' ' 2: '0',R,3 <==Moving right back to the number same for other characters 3: '0',R,3 <== Move right until I get to the space at the end of the number same for '1'-'9' ' ','0',4 4: '0',R,5 <==Write a zero in that space same for other characters 5: '0',' ',6 <== Write a space to the right of that zero same for other characters 6: ' ',L,7 <== Move left back to the end of the number same for other characters 7: '0',L,7 <== Move left until I get to the space before the beginning of the number. When I do, move right and halt. same for '1'-'9' ' ',R,H