This program is Copyright © 1976 by HewlettPackard and is used here by permission. This program was originally published in the HP67 Math Pac 1.
This program is supplied without representation or warranty of any kind. HewlettPackard Company 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.
Base Conversions 

Shift 
P? 




Label 
x_{b} 
b 
B 
>x_{B} 
x_{b}>x_{B} 
Key 
A 
B 
C 
D 
E 
This program will convert a positive number in base b, X_{b}, to its equivalent representation in base B, X_{B}. The bases b and B may take on integer values from 2 to 99, inclusive. Inputs to the program are X_{b}, b, and B; the single output is the value of X_{B}. Input of either base, b or B, may be omitted if its value is 10 since a default value of 10 is assigned to both b and B upon input of x_{b} to key A . If several conversions are to be done between the same two bases, i.e., there are several values of x_{b} for the same b and B, then the bases need not be reinput each time. Once the new value of x_{b} is keyed in, then pressing E will immediately cause the calculation of x_{B}, based on the most recent values for b and B.
The heart of this program is a routine under LBL e which actually converts numbers to and from base 10 representations. If either b or B is equal to 10, this routine is executed just once, and then the program halts displaying x_{B}. If, on the other hand, neither b nor B is 10, then x_{b} is first converted to its decimal representation, x_{10}, and next x_{10} is converted to x_{B}. Thus the routine is here executed twice.
A number such as 4B6_{16} cannot be represented directly on the display because the display is strictly numeric. Therefore, some convention must be adopted to represent numbers R_{a} when a > 10. We use the convention of allocating two digit locations for each single character in R_{a} when a > 10.
For example, 4B6_{16} is represented as 041106_{16} by our convention (in hexadecimal system,A = 10, B = ll, C = 12, D = 13, E = 14, F = 15). When displayed, this number may appear as 41106 or with an exponent
4.1106 04
which is interpreted as 4.B6 x 16^{2}.
The displayed exponent 4 is for base 10 and only serves to locate the decimal point (in the same manner as for decimal numbers).
When base a > 10 (as in the above example), divide the displayed exponent by 2 to get the true exponent of the number. When the displayed exponent is an odd integer, shift the decimal point of the displayed number one place (to the left or right) and adjust its exponent accordingly to make the true exponent an integer.
For example, the displayed number
1.112 03
is interpreted as B.C x 16^{2} or 0.BC x 16^{1}
Step 
Instructions 
Input Data/Units 
Keys 
Output Data/Units 
1 
Load side 1 and side 2. 

2 
To cause input values to be output, set Print/Pause mode. 

f A 
1.00 
3 
To cancel Print/Pause mode. 

f A 
0.00 
4 
Key in number in first base. 
x_{b} 
A 

5 
(optional) Key in first base. (If omitted, default value of b is 10. ) 
b 
B 

6 
(optional) Key in second base. (If omitted, default value of B is 10.) 
B 
C 

7 
Calculate number in second base. 

D 
x_{B} 
8 
To convert another number between the same two bases (from b to B), key in the new x_{b} and find the new x_{B} 
x_{b} 
E 
x_{B} 
9 
To change either base, go to step 4. 

The following octal numbers (b = 8) are addresses of a segment of a program in an HP2100 minicomputer: 177700, 177735, 177777. What are the values of these addresses in base 10 (B = 10)?
Keystrokes Outputs 177700 A 8 B D 65472.00 *** 177735 E 65501.00 *** 177777 E 65535.00 ***
Find the tendigit binary representation of . (x_{b} = 3.141592654, b = 10, B = 2)
Keystrokes Outputs A 2 C D DSP 9 11.00100100
Convert the following octal numbers (b = 8) into hexadecimal (B = 16): 7.200067 x 8^{10}, 1.513561778 x 8^{17}
Keystrokes Outputs 7.200067 EEX CHS 10 A 8 B 16 C D 1.13000003114 *** (l.D003A x 16^{7}) 1.513561778 EEX 17 E 1.30214140425 *** (13.02141404 24 =D.2EE4 x 16^{12})
LINE KEYS 001 *LBL A Input Xb (no. in base to be converted) 002 STO E 003 F0? 004 PRT SPC 005 F0? 006 PRTX 007 1 008 0 Default bases B and b are 10. 009 STO C 010 STO D 011 EEX 012 1 013 2 014 STO 8 015 roll dn 016 roll dn 017 RTN 018 *LBL B Input base b. 019 STO D 020 F0? 021 PRTX 022 F0? 023 PRT SPC 024 SF 2 025 RTN 026 *LBL C Input base B to which Xb is to be converted. 027 STO C 028 F2? 029 GTO 0 030 F0? 031 PRT SPC 032 *LBL 0 033 F0? 034 PRTX 035 RTN 036 *LBL D Find XB. 037 RCL C Save b and B. 038 STO A 039 RCL D 040 STO I 041 1 042 0 043 X!=Y? Is b = 10? 044 GTO 1 No, try B= 10 045 RCL C Yes, test B > 10 046 GSB d (Choose 10 or 100). 047 STO D Convert. 048 GSB e Exit. 049 GTO 5 050 *LBL 1 b != 10 051 RCL C Is B = 10? 052 X!=Y? No. branch. 053 GTO 2 Yes, test b>10 054 RCL D (Choose 10 or 100). 055 GSB d 056 STO C 057 GSB e Convert. 058 GTO 5 Exit. 059 *LBL 2 060 RCL D Here b != 10, B != 10 061 GSB d 062 STO C Convert Xb to X10. 063 GSB e 064 RCL B 065 STO E 066 RCL A 067 STO C 068 GSB d Convert X10 to XB 069 STO D 070 GSB e 071 *LBL 5 072 PRTX Exit 073 F0? 074 PRT SPC 075 R/S 076 *LBL d Subroutine tests input in 077 1 X Register > 10. 078 0 If > 10, returns value 100. 079 STO 7 If <= 10, returns value 10. 080 X<>Y 081 X>Y? 082 EEX 083 1 084 STO x 7 085 RCL 7 086 RTN 087 *LBL e Main subroutine; 088 0 Actually converts to/from 089 STO 9 base 10. 090 STO B 091 RCL E 092 *LBL 9 Shift right until < 1. 093 1 094 X>Y? 095 GTO 8 096 STO + 9 R0 track of no. of places 097 CLX shifted (exponent). 098 RCL C 099 ÷ 100 STO E 101 GTO 9 102 *LBL 8 On entry, RE contains 103 RCL C normalized Xb: 104 RCL E 0 < Xb < 1. 105 x 106 STO E 107 EEX 108 4 109 + 110 EEX 111 4 112  113 INT 114 RCL B Build up XB. 115 RCL D 116 x 117 + 118 STO B 119 RCL E 120 EEX 121 4 122 + 123 EEX 124 4 125  126 INT 127 RCL E 128  129 ABS 130 STO E 131 1 132 STO  9 Do not build mantissa 133 RCL B beyond 10^12 134 RCL 8 135 X<=Y? 136 GTO 4 137 RCL E 138 X!=0? 139 GTO 8 140 *LBL 4 141 RCL D 142 RCL 9 143 Y^{X} 144 RCL B 145 x XB 146 STO B 147 RTN 148 *LBL E Input new x for same b and B. 149 STO E 150 F0? 151 PRT SPC 152 F0? 153 PRTX 154 RCL A Last value of B. 155 STO C Last value of b. 156 RCL I 157 STO D 158 GTO D 159 *LBL a Print toggle. 160 F0? 161 GTO 0 162 SF 0 163 1 164 RTN 165 *LBL 0 166 CF 0 167 0 168 RTN
R7 10, 100 R8 10^{12} R9 Used A B B XB C B, used D b, used E Xb, used I b
Go back to the software library
Go back to the main exhibit hall