13.3k views
5 votes
2. Design a Turing Machine that given two 16-bit binary numbers written on the tape, delimited by A, computes

the sum of both numbers. For example, if the tape initially contains:
0001001001100111A0001000100100001AXXXXXXXXXXXXXXXXA
The final tape, when the Turing Machine stops (enters its final state), must contain:
XXXXXXXXXXXXXXXXAXXXXXXXXXXXXXXXXA0010001110001000A

1 Answer

4 votes

Turing machine with 5 states, 5 symbols, and 6 steps to add two 16-bit binary numbers, handling carries and writing the sum on the tape.

Turing Machine for Binary Addition (200 words):

States: Q0 (start), Q1 (add), Q2 (carry), Q3 (write), Qf (final)

Symbols: 0, 1, A (delimiter), B (temporary carry symbol), X (blank)

Tape: 16-bit binary numbers separated by A, followed by blanks

Steps:

Start (Q0): Read first bit of first number.

Add (Q1): Move right, reading second bit of first number and writing its sum with the current head symbol (initially 0) modulo 2 on the tape.

Carry (Q2): If the sum is 1, move right and write B (temporary carry) instead of the current head symbol (0 or 1).

Write (Q3): Move right until A is encountered, replacing A with X (blank).

Second Number (Q0): Repeat steps 2-4 for the second number, adding its bits and handling carries.

Final Sum (Qf): If no carry (B) remains, enter final state Qf. Otherwise, move left until B is found, replace it with 1, and move right until A, replacing it with X. Repeat until no carry remains, then enter Qf.

Output: Tape containing A followed by the 16-bit sum of the two inputs, with carry bits incorporated.

User Mackendy
by
8.2k points