| $2^0$ | 1 |
| $2^1$ | 2 |
| $2^2$ | 4 |
| $2^3$ | 8 |
| $2^4$ | 16 |
| $2^5$ | 32 |
| $2^6$ | 64 |
| $2^7$ | 128 |
| $2^8$ | 256 |
| $2^9$ | 512 |
| $2^{10}$ | 1024 |
start with 0.
For each digit left to right
multiply the value by 2.
If the digit is a 1, add in 1.
0 * 2 = 0 + 1 = 1 1 * 2 = 2 + 0 = 2 2 * 2 = 4 + 1 = 5 5 * 2 = 10 + 1 = 11 11 * 2 = 22 + 0 = 22 22 * 2 = 44 + 0 = 44 44 * 2 = 88 + 1 = 89 89 * 2 = 178 + 0 = 178
0 * 2 = 0 + 1 = 1 1 * 2 = 2 + 0 = 2; 2 * 2 = 4 + 1= 5 5 * 2 = 10 + 0 = 10 10 * 2 = 20 + 1 = 21 21 * 2 = 42 + 0 = 42 42 * 2 = 84 + 1 = 85 85 * 2 = 170 + 0 = 170 170 * 2 = 340 + 1 = 341.
'use memory location 0 for the accumulated total.
' use memory location 1 for the digit.
' store a 2 in memory location 2 for multiply
0 addi 2 C2
1 store 2 22
' clear out the accumulator
2 addi -2 C-2
'
3 top: input 30
' if the input is negative stop
4 jumpn done A11
' save the input
5 store 1 21
' load the old total
6 load 0 10
' multiply the old total by 2
7 mult 2 72
' add the new digit
8 add 1 51
' save the result
9 store 0 20
' get the next value.
10 jump top B3
11 done: load 0 10
write 40
stop 00
C2 22 C-2 30 A11 21 10 72 51 20 B3 10 40 00