HP 12C decimal hexadecimal conversion DEC -> HEX: Input integer 16-255 Result format is nibble.nibble [0-15].[00-15] e.g. 10.15 is AF 12.05 is C5 * Integers less than 16 are treated as hex HEX -> DEC: Input format is nibble.nibble [0-15].[00-15] e.g. enter 14.13 for ED 1.11 for 1B Result is an integer Side Effects: Z and T are clobbered Program ------- ; Branch to DEC->HEX if 16 <= input value ; Otherwise continue to HEX->DEC ; Leaves 16 on the stack 01 16 03 <= 04 GTO 19 ; HEX->DEC ; Stack: X:16 Y:[INPUT] 05 ROLL 06 DUP 07 INTG 08 16 10 * 11 SWAP 12 FRAC 13 100 16 * 17 + 18 GTO 00 ; DEC->HEX ; Stack: X:16 Y:[INPUT] 19 / 20 DUP 21 INTG 22 SWAP 23 FRAC 24 .16 27 * 28 + 29 GTO 00 --------------------------------------------- This version clobbers financial registers but restores Z and T on the stack Program ------- ; Save the stack Z and T 01 ROLL 02 ROLL 03 STO PV 04 ROLL 05 STO FV 06 ROLL ; Branch to DEC->HEX if 16 <= input value ; Otherwise continue to HEX->DEC ; Leaves 16 on the stack 07 16 09 <= 10 GTO 25 ; HEX->DEC ; Stack: X:16 Y:[INPUT] 11 ROLL 12 DUP 13 INTG 14 16 16 * 17 SWAP 18 FRAC 19 100 22 * 23 + 24 GTO 35 ; DEC->HEX ; Stack: X:16 Y:[INPUT] 25 / 26 DUP 27 INTG 28 SWAP 29 FRAC 30 .16 33 * 34 + ; Restore the stack 35 RCL FV 36 RCL PV 37 ROLL 38 ROLL ; Optional you may want to clear ; financial registers 39 GTO 00