Christopher Greaves Turng088.dot

Chris Greaves
32 Grenville Street; Suite 402; Toronto; Ontario; CANADA M4Y 1A3
416-993-4953
Convert Unary to Decimal Characters
Our work on converting Roman Numerals proceeds apace(!) but we are beginning
to tire of reading off our results in binary, let alone unary.
We take a break now to devise a scheme for converting unary notation to printable
decimal digits.
The scheme in essence is division by ten and the remainder is the next significant
digit.
Given a string of three hundred and twenty four “1”s we would strike out nine of
every ten digits and be left partway through a set of ten unary digits, left holding
four of them; we print ‘4’ and begin a second pass.
By now we have struck out all but every tenth unary digit, so as we work through
these, ten at a time striking out none and leaving one, we are left holding a
remainder of zero; we print ‘0’.
There are now only three unary digits remaining, and our scan of these is short; we
print ‘3’ and we are done.
We assume that our unary string is bounded at each end by the @ symbol and that
the memory pointer lies between the two @ symbols.
Here is the program:Convert Unary to Decimal Characters
Entry point; move to the rightmost @
If we found a 1 we still have work to do
Reached the rightmost @ symbol, at the
LSD
V
W
0
RV
RW
L0
1
RW
RW
P L1
1
2
3
4
5
6
7
L1
L2
L3
L4
L5
L6
L7
P L2
P L3
P L4
P L5
P L6
P L7
P L8
A
B
C
D
E
F
G
8
L8
P L9
H
9
L9
P1L0 I
A
B
C
D
E
F
G
H
I
J
P1X
P2X
P3X
P4X
P5X
P6X
P7X
P8X
P9X
P0X
LA
LB
LC
LD
LE
LF
LG
LH
LI
LJ
LA
LB
LC
LD
LE
LF
LG
LH
LI
LJ
LA
LB
LC
LD
LE
LF
LG
LH
LI
LJ
X RX RX
whY! We are finished!
Y
Here is the call to the interpreter:-
RV
RX
Sub TESTInterpreter88()
ReDim Stack(0)
ThisDocument.Save
www.ChrisGreaves.com
DocNum: 55183
Friday, July 28, 2017 Page 1 of 4
81920661
@
Y
L0
?J
err1
err2
err3
err4
err5
err6
err7
err8
err9
err1
0
err1
1
err1
2
Chris Greaves 416-993-4953
Call Interpreter("@11111111111111111111111111@", 2, 200)
End Sub
And here is the trailing end of the output; we are converting 26 (in Unary) to ASCII
character decimal.
The characters “26” can be seen at the left-hand end of the memory string.
row=3
Col=3
Cell="RW" Sym=
6@
1
1
@
^
row=3
Col=3
Cell="RW" Sym=
6@
1
1
@
^
row=3
Col=3
Cell="RW"
6@
1
Sym=
1
@
^
row=3
row=3
Col=3
Cell="RW"
6@
1
Sym=
Cell="RW"
1
Sym=
Col=3
6@
row=3
row=4
Col=5
Col=3
1
@
^
1
Cell="L0"
6@
1
@
^
Sym=@
1
Cell="L0"
6@
1
@
^
Sym=
1
@
^
row=4
Col=3
Cell="L0" Sym=
6@
1
1
@
^
row=4
Col=3
Cell="L0" Sym=
6@
1
1
@
^
row=4
Col=3
Cell="L0"
6@
Sym=
1
1
@
^
row=4
Col=3
Cell="L0"
6@
Sym=
1
1
@
^
row=4
Col=3
Cell="L0"
6@
Sym=
1
1
@
^
row=4
Col=3
Cell="L0"
6@
Sym=
1
1
@
^
row=4
Col=3
Cell="L0"
6@
Sym=
1
1
@
^
row=4
row=4
Col=3
Col=4
Cell="L0" Sym=
6@
1
Cell="P L1"
6@
1
^
Sym=1
1
@
@
^
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
www.ChrisGreaves.com
DocNum: 55182
Friday, July 28, 2017 Page 2 of 4
81920661
Chris Greaves 416-993-4953
row=5
Col=3
Cell="L1"
Sym=
6@
1
@
^
row=5
Col=3
Cell="L1"
Sym=
6@
row=5
Col=4
Cell="P L2"
1
^
@
Sym=1
6@
@
^
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
@
^
row=6
Col=3
Cell="L2"
Sym=
6@
^
@
row=6 Col=5 Cell="B" Sym=@
row=16 Col=5 Cell="LB" Sym=@
6@
^
row=16
Col=6
Cell="LB"
@
Sym=6
6@
@
26@
^
@
^
row=16
row=26
Col=3
Col=6
Cell="P2X"
Cell="RX"
Sym=
Sym=2
26@
^
row=26
Col=6
Cell="RX"
@
Sym=6
26@
^
row=26
Col=5
Cell="RV"
@
Sym=@
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
www.ChrisGreaves.com
DocNum: 55182
Sym=
Friday, July 28, 2017 Page 3 of 4
81920661
Chris Greaves 416-993-4953
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV"
Sym=
26@
@
^
row=2
Col=3
Cell="RV" Sym=
26@
@
^
row=2
Col=3
Cell="RV" Sym=
26@
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
Col=3
Cell="RV"
26@
Sym=
@
^
row=2
row=2
Col=3
Cell="RV"
26@
Sym=
Col=3 Cell="RV"
26@
Sym=
@
^
@
^
row=2 Col=5 Cell="Y"
row=27 Col=5 Cell=""
Sym=@
Sym=@
www.ChrisGreaves.com
DocNum: 55182
Friday, July 28, 2017 Page 4 of 4
81920661