Reference Guide

RPL Programming Examples 2-23
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.
«
""
DO
'm' EVAL b i
'k' EVAL - ^
Begin inner local variable structure,
enter an empty string and begin the
DO...UNTIL...END loop.
Compute the decimal value of the
(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 ==
'm' EVAL b Š
AND
Is the remainder zero and m
b?
THEN 1 SF
If the test is true, then set flag 1.
END 'm' STO
/ IP
Store the remainder in m. Compute the
number of times the current position-
value goes into the remaining decimal
value. This is thedigit” that belongs in
the current position.
IF DUP 10 Š
Is the “digit” ≥ 10?
THEN 55
ELSE 48
END + CHR
Then convert the digit into a alphabetic
digit (such as A, B, C, …).
+ 'k' 1 STO+
Append the digit to the current result
string and increment the counter
variable k.