RPL Programming Examples 2-5
Example: Calculate F
13
and compare the execution time for the two methods.
Select the VAR menu and do the calculation.
J
13 %FIBT%
F
13
is 233. FIB2 takes fewer seconds to execute than FIB1 (far fewer if n is large). (The times required for the
calculations depend on the contents of memory and other factors, so you may not get the exact times shown
above.)
Displaying a Binary Integer
This section contains three programs:
! PAD is a utility program that converts an object to a string for right-justified display.
! PRESERVE is a utility program for use in programs that change the calculator's status (angle mode, binary
base, and so on).
! BDISP displays a binary integer in HEX, DEC, OCT, and BIN bases. It calls PAD to show the displayed
numbers right-justified, and it calls PRESERVE to preserve the binary base.
PAD (Pad with Leading Spaces)
PAD converts an object to a string, and if the string contains fewer than 22 characters, adds spaces to the
beginning of the string till the string reaches 22 characters.
When a short string is displayed with DISP, it appears left-justified: its first character appears at the left end of
the display. By adding spaces to the beginning of a short string, PAD moves the string to the right. When the
string (including leading spaces) reaches 22 characters, it appears right-justified: its last character appears at the
right end of the display. PAD has no effect on longer strings.
Level 1 " Level 1
object
"
"object"
Techniques used in PAD
! WHILE…REPEAT…END (indefinite loop). The WHILE clause contains a test that executes the
REPEAT clause and tests again (if true) or skips the REPEAT clause and exits (if false).
! String operations. PAD demonstrates how to convert an object to string form, count the number of
characters, and combine two strings.