The Museum of HP Calculators


HP-41CX Decimal <-> Hexadecimal Conversions

This program is Copyright © 1999 by Michael Harwood and Paul Picot and may be freely used by permission.

This program is supplied without representation or warranty of any kind. Michael Harwood, Paul Picot,  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.

Usage

    The most frequent base changes are between the decimal, binary, and hexadecimal systems. Hexadecimal <-> binary conversions are trivial, so all that is needed is a program to convert decimal to hexadecimal and vice versa.
There are actually two programs: (i) "H^D" (hex to decimal) and (ii) "D^H" (decimal to hex).
    I assign them to the "P^R" and "R^P" keys.

These programs are short and use no flags nor any storage registers.
The decimal number is entered in the X-register. The hexadecimal number must be entered in the Alpha register.  The results of the conversion are also displayed in these two registers.

Example

1) Convert 42 to hexadecimal
2) Then convert C5 to decimal

KEYSTROKES       DISPLAY        COMMENTS

42               42
XEQ "D^H"        2A             The answer!

ALPHA            2A             (last thing in Alpha register)
C5               C5
ALPHA            0
XEQ "H^D"        197            The answer!

Therefore 42D = 2AH and C5H = 197D

You can only enter the digits 0-9 and A-F for the HEX to DEC conversion. If you enter an invalid character, the computer will sound tone 0 and display some number. (The only invalid characters that are not detected are : ; < = > ? and @  . This is because the error checking would just make the program longer.)

How to get this Program to your Calculator (via HP-IL, disk, wand, and fingers)
Download Binary (.raw) program for disk or PC HP-IL Card download. (This version was combined into a single program by Pierre Hardy by replacing the END on line 31 with RTN and concatenating.)

The Programs

01LBL"H^D"        hexadecimal to decimal (the number to convert must
02 0                                       already be in the Alpha
03LBL 01                                 register)
04 ATOX
05 X=0?
06 GTO 02
07 70
08 X<Y?
09 GTO 04          invalid character
10 RDN
11 57
12 -
13 X<=0?
14 GTO 03
15 7
16 -
17LBL 03
18 9
19 +
20 X<0?
21 GTO 04           invalid character
22 X<>Y
23 16
24 *
25 +
26 GTO 01
27LBL 04
28 TONE 0
29LBL 02
30 RDN             (Bug fix supplied by Pierre Hardy)
31 END


01LBL"D^H"       decimal to hexadecimal (number to convert is in X-reg)
02 CLA
03LBL 01
04 ENTER^
05 ENTER^
06 16
07 ST /Z
08 MOD
09 9
10 -
11 X<=0?
12 GTO 02
13 7
14 +
15LBL 02
16 57
17 +
18 XTOA
19 -1
20 AROT
21 RDN
22 RDN
23 INT
24 X!=0?
25 GTO 01
26 AVIEW
27 END
 

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall