The Museum of HP Calculators

Converting Between Integers and Floats for the HP-16C

The Buttons that HP forgot!

This program is supplied without representation or warranty of any kind. Jamie Cox and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Bug Report

It has been reported that this program does not deal correctly with fractional parts of numbers or negative numbers. There is a new (longer) program that is recommended for dealing with these cases.

Overview

The HP-16C is HP's famous programmable programmer's calculator. It includes basic arithmetic functions in floating point as well as logical and math operations on integers in four bases. The biggest weakness of the calculator is that it isn't easy to convert between float and integer displays. This program overcomes this limitation by providing short subroutines for these functions.

These functions make the calculator much easier to use.

This program provides handy subroutines to convert between integer and floating point modes for the HP-16C. Although the calculator does most of the work, the result doesn't automatically appear in the display as you would expect. Use these subroutines to set the calculator to the desired mode while converting the display to the new mode. Any fractional part is truncated when changing to integer.

Conversion to integer uses 32-bits words in hex with leading zeros. This is a personal preference. You could just as well use, say, 16-bit words in octal without leading zeros.

INSTRUCTIONS:

After entering the program,

Press GSB A to convert a floating point number to integer (hex).
Press GSB 9 to convert an integer (any base) to a floating point number.
Warning: If the number in the display is too big to fit in 32 bits, it will be silently truncated during either conversion.

HP-16C Program

```# HP-16C Integer-to-Float/Float-to-Integer
#      -Jamie Cox
# Usage:
# Press GSB A to convert a float number to 32-bit HEX
# Press GSB 9 to convert an integer to float
# Mnemonic: A is a hex digit, 9 is a decimal digit.
#   A & 9 are at opposite ends of the keypad
#
#

001 43,22,A   g LBL A	        # Convert Float to Integer
002 23	      HEX	        # Leaves value in Y and shift count in X
003 42 F      RRn               # Apply shift
004 2	      2			# 20 Hex gives 32-bit wordsize
005 0	      0
006 42 44     f WSIZE
007 43,4,3    f SF 3		# display leading zeros
008 43 21     g RTN

009 43,22,9   g LBL 9		# Convert Integer to Float
010 0	      0
011 42, 45,3  f FLOAT 3		# Set # digits after decimal
012 43 21     g RTN		# That was easy

```

Written by Jamie Cox