-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbinary_to_decimal
More file actions
39 lines (37 loc) · 948 Bytes
/
Copy pathbinary_to_decimal
File metadata and controls
39 lines (37 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
; -*- mode: turing-machine -*-
; http://morphett.info/turing/turing.html
; Converts a number from binary to decimal.
; It does this by successively incrementing the decimal counter and decrementing the binary input until 0 is reached.
; Input: A single number in binary.
;; INITIAL: 1111
;; RATE: .1
0 * * * 1
1 _ _ r 1
1 * * r 1a
1a * * r 1a
1a _ _ l 2 ; found the end of the input
1b _ _ r 1 ; (used later) skip the output, go to end of input
1b * * r 1b
2 1 0 l 3 ; decrement input
2 0 1 l 2 ; decrement & carry
2 _ _ r 20 ; finished. clean up
3 * * l 3 ; find start of output
3 _ _ l 4 ; found end of input
4 0 1 r 1b ; increment the output
4 1 2 r 1b
4 2 3 r 1b
4 3 4 r 1b
4 4 5 r 1b
4 5 6 r 1b
4 6 7 r 1b
4 7 8 r 1b
4 8 9 r 1b
4 9 0 l 4 ; increment & carry
4 _ 1 r 1b ; start new column
; clean up
20 _ _ l 21 ; return to end of output
20 * _ r 20 ; erase input
21 _ _ l 21
21 * * l 21a
21a * * l 21a
21a _ _ r halt