nBASE program listing
Program: | Comments: | |
|
|
|
« |
|
|
1 CF | 0 RND SWAP 0 RND RCLF | Clear flag 1, round both arguments to |
|
| integers and recall flag settings. |
→ b n f | Store the base, number and flag settings | |
|
| in local variables. |
« |
| Begin the outer local variable structure. |
STD n LOG b LOG / | Sets “standard” display mode and | |
|
| computes the ratio of the common |
|
| logarithms of number and base. |
10 | RND | Rounds result to remove imprecision in |
|
| last decimal place. |
IP n 0 | Find the integer part of log ratio, recall | |
|
| the original number, and initialize the |
|
| counter variable k for use in the |
|
| DO...UNTIL loop. |
→ i m k | Store the values in local variables. | |
« |
| Begin inner local variable structure, |
"" | enter an empty string and begin the | |
DO | DO...UNTIL...END loop. | |
| 'm' EVAL b i | Compute the decimal value of the |
| 'k' EVAL - ^ | |
| (i – k) th position in the string. | |
|
| |
| DUP2 MOD | Makes a copy of the arguments and |
|
| computes the decimal value still |
|
| remaining that must be accounted for |
|
| by other positions. |
| IF DUP 0 == | Is the remainder zero and m ≥ b? |
| 'm' EVAL b Š |
|
| AND |
|
| THEN 1 SF | If the test is true, then set flag 1. |
| END 'm' STO | Store the remainder in m. Compute the |
| / IP | number of times the current position- |
|
| value goes into the remaining decimal |
|
| value. This is the “digit” that belongs in |
|
| the current position. |
| IF DUP 10 Š | Is the “digit” ≥ 10? |
| THEN 55 | Then convert the digit into a alphabetic |
| ELSE 48 | digit (such as A, B, C, …). |
| END + CHR |
|
| + 'k' 1 STO+ | Append the digit to the current result |
|
| string and increment the counter |
|
| variable k. |
|
|
|
RPL Programming Examples