HP16C Users Guide
A PDF of the original HP16C Users Guide can be found at https://literature.hpcalc.org/items/589
Introduction
WRPN is a calculator for Microsoft Windows that is modeled after the Hewlett-Packard HP-16c. This is not a Hewlett-Packard product.
WRPN uses Reverse Polish Notation, which uses the ENTER key instead of the "=" (equals) key.
In addition to all the functions you'd expect from an ordinary calculator, WRPN also has many features specifically designed for the computer professional:
- Floating point, Decimal, Hexadecimal, Octal, and Binary modes
- Word sizes from 1-64 bits per word
- Signed math (1's complement, 2's complement, unsigned)
- Logical operators (and, or, xor, not, masks, etc.)
- Bit-wise operators (shift, rotate, rotate with carry, etc.)
- 32 storage registers
- 4 position stack
- 203 lines of program memory
The right-most position in the display indicates the current operating mode:
(blank) Floating Point h Hexadecimal o Octal d Decimal b Binary
WRPN Architecture
WRPN uses up to 64 bits as the internal representation for integer numbers. When dealing with floating point numbers, the numbers are stored in a typical 8-byte (64 bit) IEEE floating point format. The precision of floating point numbers is fixed, but integers can range from 1 to 64 bits in length
WRPN has 6 internal registers, 4 of which are arranged in a Last In First Out (LIFO) stack. They are:
- stack 3 (the T register)
- stack 2 (the Z register)
- stack 1 (the Y register)
- stack 0 (the X register)
- Last X
- Index
Values pushed "off the top" of the stack (beyond stack 3) are lost. However, the value at the top of the stack is preserved when values are "popped".
The bottom of the stack (the X register) is the value that is always shown in the display.
The Last X variable contains the previous value of the X register after a math operation.
There are 6 flags:
- flag 0 User defined
- flag 1 User defined
- flag 2 User defined
- flag 3 When cleared, trim leading zeros from display
- flag 4 The "carry" bit
- flag 5 Overflow condition
Reverse Polish Notation
Reverse Polish Notation is a mathematical notation that more closely models the way you solve algebraic equations. It uses "Enter" to separate numbers and mathematical operators appear at the end. WRPN uses a stack to store intermediate values which eliminates the need for parentheses to group intermediate calculations.
For example, to add 2 plus 3:
Tradition notation Reverse Polish Notation 2 2 + Enter 3 3 = +
Notice that the two numbers are separated by the Enter button and that the operator (the "+" button) comes at the end.
The elegance of this notation becomes more apparent in the following example (2 + 3) x 4:
You type Shown in display X register Y register 2 2 2 0 Enter 2.0000 2 2 3 3 3 2 + 5.0000 5 0 4 4 4 5 x 20.0000 20 0
Key Sequences
Almost every button in WRPN has three functions:
- normal (unshifted) function
- "yellow" function
- "blue" function
To select a "yellow" function, first use the mouse to click on the yellow "f" button, then click on the desired button.
To select a "blue" function, click on the blue "g" button, then click on the desired button.
The following buttons require an "argument". This means that after you click on the button, you must also click some "digit" button (which becomes the "argument" to the function).
- STO
- RCL
- FLOAT
- SF
- CF
- F?
- WINDOW
For example, to recall a value from register 5, you would use the following sequence:
RCL
5
The "5" never appears on the screen, because it is the argument of the RCL operator.
Certain buttons are also mapped to the keyboard; they are:
- 0-9
- A-F
- .
- +
- -
- ×
- ÷
- BSP
Note: Use the "*" key for ×, and "/" for ÷
The Enter button is only required to separate the numbers (and push the value onto the stack)
Operating Modes
WRPN has 5 operating modes:
- Floating point
- Decimal
- Hexadecimal
- Octal
- Binary
Click on the HEX, DEC, OCT, or BIN buttons to enter the appropriate integer mode.
The FLOAT function is a "yellow" function above the RCL button. FLOAT requires an argument which is the decimal precision. For example, to switch to floating point mode with 2 decimal places, enter the following sequence:
FLOAT (use f, then RCL)
2
The float mode will switch to scientific notation whenever the display would otherwise loose precision at the specified number of decimal places. To force scientific notation, enter a decimal point as the float digit. To enter a number in scientific notation use the EEX key (FKey + CHS) to enter the exponent.
Optionally, each of the operating modes can be selected from the window's Menu.
The internal representation of the numbers do change when switching between the floating point and any one of the integer modes. In some cases, the values may appear to be the same. However, do not rely on this behavior. For example, the fractional parts of floating point number will be truncated upon entering one of the integer modes... and will not be restored upon return to the floating point mode.
The range of valid input characters is shown below:
Hex [0-9] [a-f] Float [0-9] (plus decimal point) Dec [0-9] Oct [0-7] Bin [0-1]
Display
While the yellow F key is pressed, the "f" indicator is shown in the bottom portion of the display. When the blue G key is pressed, the "g" indicator is shown.
The status of the overflow and carry bit indicator are shown as "C" and "G". The program mode is indicated by the "PRGM" indicator.
Control over displaying leading zeros is determined by flag 3.
The numeric display can only contain 32 bits on information while in the 64 bit binary mode. To indicate that more digits are present, the "mode indicator" changes from "b" to ".b" or "b.". The WINDOW key (f + Enter) and the Scroll keys (g + STO and g + RCL)are used to see the other 32 bits.
Basic/Input Functions
Function | Key | Description |
---|---|---|
ON | No function. Use the normal File/Exit or the close button to exit WRPN. | |
f | Gain access to the "yellow" functions. The f button doesn't have a function of its own, it is used to change the function of another button (i.e.: the function written in yellow immediately above the button). | |
g | Gain access to the "blue" functions. It is used to change the function of a button to the function written in blue immediately below the button. | |
Enter | Used to terminate numeric input and push a value onto the stack. | |
BSP | Backspace. Erases one character of input. Also used to clear error messages from the screen. | |
clear PREFIX | Clear a pending two-part function. When functions that require multiple buttons are entered in error, they must be terminated in this way. | |
[0-9] | The digits [0-9] are used to input values or as arguments to other functions. Obviously, the OCT and BIN modes do not allow digits beyond 7 and 1 respectively. | |
decimal | The decimal point button is only used in the Float mode. | |
[A-F] | The letters [A-F] are used as digits in the HEX mode. | |
EEX | Enter Exponent. This button is used for entering scientific notation (float mode only). | |
CHS | Change sign. Used to toggle between a negative and positive value. If pressed after EEX, it toggles the sign of the exponent. |
Options
Function | Key | Description |
---|---|---|
HEX | Hexadecimal mode. All values are displayed as hexadecimal (base 16) numbers. The HEX mode does not support fractional values. | |
DEC | Decimal mode. All values are displayed as decimal (base 10) numbers. The DEC mode does not support fractional values. The method of representing negative numbers is discussed below. | |
OCT | Octal mode. All values are displayed as octal (base 8) numbers. The OCT mode does not support fractional values. | |
BIN | Binary mode. All values are displayed as binary (base 2) numbers. The BIN mode does not support fractional values. | |
FLOAT | Floating point mode. All values are displayed as floating point numbers at the requested number of decimal places. The is a "two part" function that requires a single digit [0-9] as an argument. The argument is the number of decimal places to be shown in the display. The display will automatically change to scientific notation if the requested decimal places would otherwise obscure the precision. | |
WSIZE | Word size. Changes the internal word size (bits per word). WSIZE takes the value of the X register as the argument. | |
set 1's | Set 1's complement. Change the representation of negative numbers to 1's complement. | |
set 2's | Set 2's complement. Change the representation of negative numbers to 2's complement. This is the normal representation. | |
set UNSGN | Set to unsigned complement. Change the representation of "negative" numbers to unsigned. | |
show HEX | Show the value in the X register as a hexadecimal number, but remain in the current mode. | |
show DEC | Show the value in the X register as a decimal number, but remain in the current mode. | |
show OCT | Show the value in the X register as a octal number, but remain in the current mode. | |
show BIN | Show the value in the X register as a binary number, but remain in the current mode. | |
STATUS | Display the current status of the word size, complement mode, and user flags. | |
< | Move the display "window" 1 bit to the left. In the binary mode, the presence of additional digits to the left is indicated by the ".b" mode indicator. | |
> | Move the display "window" 1 bit to the right. . In the binary mode, the presence of additional digits to the right is indicated by the "b." mode indicator. | |
SF | Set Flag. Set the flag specified in the X register to 1. | |
CF | Clear Flag. Set the flag specified in the X register to 0. | |
WINDOW | Move the display 32 bits in the binary mode. Window 0 is the right-most (normal) windows, and Window 1 is the left-most. |
Math Functions
Function | Key | Description |
---|---|---|
+ | Addition. Add the value of the X register to the value of Y register and return the answer in the X register. Contents of the Y register are lost. | |
- | Subtraction. Subtract the value of the X register from the value of Y register and return the answer in the X register. Contents of the Y register are lost. | |
× | Multiplication. Multiply the value of the X register to the value of Y register and return the answer in the X register. Contents of the Y register are lost. | |
÷ | Division. Divide the value of the X register into the value of Y register and return the answer in the X register. Contents of the Y register are lost. | |
Sqrt | Square root. Performs the square root of the value of the X register and returns the answer to the X register. | |
1/x | Inverse. Performs the inverse of the value of the X register and returns the answer to the X register. (Not available in the integer modes) | |
ABS | Absolute value. Performs the absolute value of the value of the X register and returns the answer to the X register. | |
RMD | Remainder (modulus). Performs a modulus on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost. | |
DBL× | Double precision multiplication. Multiply the value of the X register to the value of the Y register and returns the answer split between the X and Y registers. The X register contains the right-most bits (as defined by word size), the Y register contains the left-most bits. | |
DBL÷ | Double precision division. Divide the value split between the Y and Z registers into the value of the X register and return the answer in the X register. The Y register contains the left-most bits (as defined by word size), the X register contains the right-most bits. | |
DBLR | Double precision remainder (modulus). Performs the modulus of the value split between the X and Z registers into the value of the X register and return the answer in the X register. The Y register contains the left-most bits (as defined by word size), the X register contains the right-most bits. |
Stack/Register Functions
Function | Key | Description |
---|---|---|
Rol | Roll the stack down. The contents of the stack are rolled from top to bottom (and wrap around to the top). | |
Rol up | Roll the stack up. The contents of the stack are rolled from bottom to top (and wrap around to the bottom). | |
X:Y | Exchange X and Y. Exchange the values of the X and Y registers. | |
CLx | Clear the X register. The contents of the X register are set to zero. | |
LSTx | Last X. The previous contents of the X register are placed into the X register. | |
STO | Store. Store the value of the X register into a "storage register". This is a "two part" function which requires a single digit [0-9][A-F] as an argument or a decimal point and single digit [.0-.9][.A-.F]. The argument is the "name" of the register to receive the value. | |
RCL | Recall. Recall the value from a "storage register" into the X register. This is a "two-part" function which requires a single digit [0-9][A-F] as an argument or decimal point and single digit [.0-.9][.A-.F]. The argument is the "name" of the register from which to get the value. | |
Clear REG | Clear registers. Clears all "storage registers". All registers are set to values of zero. |
Logical Operators
Logical operators only function in one of the integer modes
Function | Key | Description |
---|---|---|
AND | Performs a logical "and" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost. | |
OR | Performs a logical "or" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost. | |
XOR | Exclusive or. Performs a logical "exclusive or" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost. | |
NOT | Not (1's complement). Performs a 1's complement on the contents of the X register. The answer is returned to the X register. |
Bit-wise Operators
Bit operators only function in one of the integer modes.
Function | Key | Description |
---|---|---|
SL | Shift Left. Shift the bit pattern in the X register to the left. The left-most bit is preserved in the carry bit variable. The new right-most bit is replaced with a zero. | |
SR | Shift Right. Shift the bit pattern in the X register to the right. The right-most bit is preserved in the carry bit variable. The new left-most bit is replaced with a zero. | |
ASR | Arithmetic Shift Right. Shift the bit pattern in the X register to the right but preserve the left-most (sign) bit. The right-most bit is preserved in the carry bit variable. | |
RR | Rotate Right. Rotate the bit pattern in the X register to the right. The right-most bit is copied to the new left-most position and preserved in the carry bit variable. | |
RRn | Rotate Right "n" times. Rotate the bit pattern in the Y register to the right the number of times indicated by the value of the X register. The right-most bits are copied to new left-most positions. The carry bit contains the last right-most bit rotated. | |
RRC | Rotate Right with Carry. Rotate the bit pattern in the X register to the right and include the carry bit (between the left-most and right-most positions). The right-most position is preserved in the carry bit variable. | |
RRCn | Rotate Right with Carry "n" times. Rotate the bit pattern in the Y register to the right (including the carry bit) the number of times indicated by the value of the X register. The carry bit contains the last right-most bit rotated. | |
RL | Rotate Left. Rotate the bit pattern in the X register to the left. The left-most bit is copied to the new right-most position and preserved in the carry bit variable. | |
RLn | Rotate Left "n" times. Rotate the bit pattern in the Y register to the left the number of times indicated by the value of the X register. The left-most bits are copied to new right-most positions. The carry bit contains the last right-most bit rotated. | |
RLC | Rotate Left with Carry. Rotate the bit pattern in the X register to the left and include the carry bit (between the left-most and right-most positions). The left-most position is preserved in the carry bit variable. | |
RLCn | Rotate Left with Carry "n" times. Rotate the bit pattern in the Y register to the left (including the carry bit) the number of times indicated by the value of the X register. The carry bit contains the last left-most bit rotated. | |
MASKR | Mask Right. Create a right justified bit-wise mask. The number of bits in the mask is the value of the X register. | |
MASKL | Mask Left. Create a left justified bit-wise mask. The number of bits in the mask is the value of the X register. | |
LJ | Left Justify. Move the bit pattern to the left most position within the current word size. Afterwards, the number of positions shifted is put in the X register and the resulting shifted pattern is put in the Y register. | |
SB | Set Bit. Set a bit to 1 in the value of the Y register. The number of the bit to set is the value of the X register. The answer is returned in the X register. | |
CB | Clear Bit. Clear a bit (set to 0) in the value of the Y register. The number of the bit to clear is the value of the X register. The answer is returned in the X register. | |
#B | Sum Bits. Perform a summation of the number of set (value of 1) bits in the value of the X register. Returns the answer in the X register. |
Programming
The writing and editing of a program within the calculator is performed similar to recording a series of keystrokes. This recording process is started and stopped with the P/R key, which switches the display to show the program line number, followed by codes for the recorded keys. You can navigate through the program listing via the SST, BST, and GTO keys.
Recorded program lines are (optionally) saved upon exit or can be explicitly saved to a file. Loading a saved file will not only retrieve the program lines, it will also retrieve all other calculator settings. Programs lines can be printed via the File/Print Program menu item.
Running an program within the calculator is preformed by the GSB key followed by a label (0-9, A-F). A crude form of debugging is available via the SST key which allows for the application to be executed one line at a time. Program execution can be paused or stopped via the PSE and R/S keys.
Note: It is beyond the scope of this document to provide sufficient information on how to write a program for WRPN.
Function | Key | Description |
---|---|---|
GSB | Go to subroutine (followed by a label key). Used to launch a program | |
GTO | Go to label | |
R/S | Run or Stop the program | |
SST | Single step through a program | |
x:(i) | Exchange X with the value of the Index register | |
x:I | Exchange X with Index register | |
(i) | The value of the Index register | |
I | The I (index) register | |
B? | Test bit | |
RTN | Return from subroutine | |
LBL | Label (the target of a GTO or GSB) | |
DSZ | Decrement and skip on zero | |
ISZ | Increment and skip on zero | |
F? | Test flag (i.e. the carry bit) | |
P/R | Switch between the Program or Run modes | |
BST | Back step through a program | |
PSE | Pause execution to show a value | |
MEM | Program memory | |
x<=y | If (x <=y ) then... | |
x<0 | If (x < 0) then... | |
x>y | If (x > y) then... | |
x>0 | If (x> 0) then... | |
x!=y | If (x!= y) then... | |
x!=0 | If (x != 0) then... | |
x=y | If (x= y) then... | |
x=0 | If (x = 0) then... |
Configuration Options
Users can optionally edit the XML-based "wrpn.config (or WRPN.exe.config)" file to change some of the calculator's features/properties. The location and exact name of this file is platform-dependent. Android users have a built-in configuration menu (since it is often difficult to get to the wrpn.config file without a 3rd party app)
Note: Be careful, since there's no input validation to prevent bogus entries
- PrgmMemoryLines: The number of "lines" of memory available for programs. The default is 203 (which matches the physical calculator). The max possible is 999.
- SyncConversions: Do you want to "synchronize" the values between floating point and binary mode. The default is True (which does not match the physical calculator)
- SleepDelay: The amount of time (in milliseconds) for error/status messages to appear on the calculator's screen. The default is 1500
- NumRegisters: The number of registers available. The default is 32 (which matches the physical calculator). There is no practical max limit.
- Orientation: (Android Only) Do you want to "lock" the orientation. Valid options are Auto, Landscape, and Portrait. The default is Auto
- FontSize: Override the default font size. A size of 0 means to "autoscale" the font (this is the default) otherwise, enter a font size (i.e. 21)
- NumberFormat: Override the default Locale's formatting of numbers. A value of Auto means the current locale (this is the default), use ",." to force the US convention, or use use ".," to force the reverse convention
Note: Changes do not go into effect until the program is restarted
State Files
Programs and calculator settings are stored in XML-based "saved state" files. The location of these files is platform-dependent. The default name is CalcState.xml, but you create many state files. The calculator does not have a built-in feature for managing these files, so you must use the normal operating system tools to copy, move, delete, or rename these files.
Note: Editing of these files is allowed, but be careful... since there are very few input validation checks