Back to the index

Base Converter for the HP-32SII

Store an integer between 2 and 16 in variable B. Routine T converts a nonnegative integer from base 10 "to" base B. Routine F converts "from" base B (displayed in HEX mode) back to base 10.

E.g. "12 STO B 2013 XEQ T" displays "11B9" (2013 in base 12). Still in hex mode, type "1200 XEQ F", and it displays "2016".

Since the calculator only supports bases 2, 8, 10, and 16, arithmetic in other bases is rather awkward: "HEX 117A 11B9 XEQ F x<>y XEQ F - XEQ T" should display "3B" as the result of a base-12 subtraction.

Routine M could be inlined here, but it's useful by itself. Without upsetting the stack, it replaces y and x with the integer quotient and remainder of y/x. The INT÷ and RMDR operations give only one of these outputs, and they were introduced with the 33s model.

T01 LBL T
T02 0
T03 STO A
T04 R↓
T05 1
T06 STO C
T07 R↓
T08 SF 0
T09 XEQ B
T10 RCL A
T11 HEX
T12 RTN

F01 LBL F
F02 0
F03 STO A
F04 R↓
F05 1
F06 STO C
F07 R↓
F08 CF 0
F09 XEQ B
F10 RCL A
F11 DEC
F12 RTN

B01 LBL B
B02 16
B03 RCL B
B04 FS? 0
B05 x<>y
B06 R↓
B07 XEQ M
B08 RCL× C
B09 STO+ A
B10 R↑
B11 STO× C
B12 R↓
B13 R↓
B14 x>0?
B15 GTO B
B16 R↓
B17 RTN

M01 LBL M
M02 x<>y
M03 STO M
M04 x<>y
M05 ÷
M06 LASTx
M07 x<>y
M08 IP
M09 ×
M10 LASTx
M11 x<>y
M12 RCL- M
M13 +/-
M14 RTN

The HP 50g uses a more complex programming language called "User RPL". It's still essentially a series of keystrokes applied to an RPN stack, but with local variables and no line numbers or "goto" statements. The above programs look like

Program "tbase":
« "" → str «
  DO base IDIV2 DUP 9 > 7 * + 48 + CHR str + 'str' STO
  UNTIL DUP 0 ≤                       
  END
  DROP str
» »

Program "fbase":
« 0 → num «
  WHILE DUP SIZE 0 > 
  REPEAT base 'num' STO* DUP NUM R→I DUP 64 > 7 * - 48 - 'num' STO+ TAIL
  END
  DROP num
» »
"base" must be a global variable containing an integer between 2 and 36. This calculator supports enormous integers, so you can e.g. verify that 263-1 is 9223372036854775807 in decimal and "1Y2P0IJ32E8E7" in base 36.