(15C)(DM15) - Convert Number from one Base to Another - deetee - 11-22-2021 10:45 AM
Hi!
As owner of a new DM15 I proudly present my first program, which converts one number from one base to another. This could give the DM15 a little bit of the HP-16C features. Unfortunately the calculator doesn't support figures >9 (ie. letters A ... F). So involving number bases >10 (ie HEX) doesn't work properly.
Example:
To convert 1101 from base 2 to base 8 simple enter 1101, 2 and 8 to the stack and start the program. The outputs on the stack are the original number (Z: 1101), the number converted to decimal (Y: 13) and the number converted to octal (X: 15).
The program source code - as output of Thorsten Manz' great HP15C-Simulator - is:
Code:
# ------------------------------------------------------------------------------
# HEWLETT·PACKARD 15C Simulator program
# Created with version 4.3.00
# ------------------------------------------------------------------------------
#T:Base Conversion
#D:Converts a number from one base to another.
#D:
#D:INPUT:
#D: Z: Number
#D: Y: FromBase
#D: X: ToBase
#D:
#D:OUTPUT:
#D: Z: Number
#D: Y: NumberInDecimal
#D: X: NumberConverted
#D:
#D:Example: [1101 2 8] -> [1101 13 15]
#D:
#D:Uses STO 1...9 and LBL 6...9
#D:
#L6:Convert
#L9:Modulo
#R1:Number
#R2:ToBase
# ------------------------------------------------------------------------------
000 { }
001 { 42 21 12 } f LBL B
002 { 44 2 } STO 2
003 { 33 } R⬇
004 { 33 } R⬇
005 { 44 1 } STO 1
006 { 43 33 } g R⬆
007 { 1 } 1
008 { 0 } 0
009 { 32 6 } GSB 6
010 { 33 } R⬇
011 { 45 2 } RCL 2
012 { 36 } ENTER
013 { 32 6 } GSB 6
014 { 45 1 } RCL 1
015 { 36 } ENTER
016 { 33 } R⬇
017 { 33 } R⬇
018 { 43 32 } g RTN
019 { 42 21 6 } f LBL 6
020 { 44 5 } STO 5
021 { 33 } R⬇
022 { 44 4 } STO 4
023 { 33 } R⬇
024 { 44 3 } STO 3
025 { 0 } 0
026 { 44 9 } STO 9
027 { 44 8 } STO 8
028 { 44 7 } STO 7
029 { 1 } 1
030 { 44 6 } STO 6
031 { 45 3 } RCL 3
032 { 45 5 } RCL 5
033 { 42 21 8 } f LBL 8
034 { 32 9 } GSB 9
035 { 44 40 8 } STO + 8
036 { 1 } 1
037 { 0 } 0
038 { 44 10 8 } STO ÷ 8
039 { 33 } R⬇
040 { 1 } 1
041 { 44 40 7 } STO + 7
042 { 33 } R⬇
043 { 45 6 } RCL 6
044 { 20 } ×
045 { 44 40 9 } STO + 9
046 { 45 4 } RCL 4
047 { 44 20 6 } STO × 6
048 { 33 } R⬇
049 { 33 } R⬇
050 { 45 5 } RCL 5
051 { 34 } x↔y
052 { 43 20 } g x=0
053 { 22 7 } GTO 7
054 { 34 } x↔y
055 { 22 8 } GTO 8
056 { 42 21 7 } f LBL 7
057 { 34 } x↔y
058 { 1 } 1
059 { 0 } 0
060 { 45 7 } RCL 7
061 { 14 } yˣ
062 { 44 20 8 } STO × 8
063 { 45 3 } RCL 3
064 { 45 9 } RCL 9
065 { 45 8 } RCL 8
066 { 43 32 } g RTN
067 { 42 21 9 } f LBL 9
068 { 36 } ENTER
069 { 36 } ENTER
070 { 43 33 } g R⬆
071 { 36 } ENTER
072 { 33 } R⬇
073 { 34 } x↔y
074 { 10 } ÷
075 { 43 44 } g INT
076 { 36 } ENTER
077 { 33 } R⬇
078 { 20 } ×
079 { 30 } −
080 { 43 32 } g RTN
# ------------------------------------------------------------------------------
Probably the code can be optimized - but so far I'm happy that it works.
Regards
deetee
RE: (15C)(DM15) - Convert Number from one Base to Another - Thomas Klemm - 07-05-2022 05:49 PM
This is a verbatim translation of this (HP-67) Base Conversion program for the HP-15C:
Code:
001 { 42 21 11 } f LBL A
002 { 44 3 } STO 3
003 { 33 } R⬇
004 { 44 1 } STO 1
005 { 36 } ENTER
006 { 32 3 } GSB 3
007 { 32 0 } GSB 0
008 { 45 3 } RCL 3
009 { 32 3 } GSB 3
010 { 44 1 } STO 1
011 { 45 3 } RCL 3
012 { 42 21 0 } f LBL 0
013 { 44 2 } STO 2
014 { 30 } −
015 { 34 } x↔y
016 { 44 0 } STO 0
017 { 42 21 1 } f LBL 1
018 { 45 1 } RCL 1
019 { 34 } x↔y
020 { 45 2 } RCL 2
021 { 10 } ÷
022 { 43 44 } g INT
023 { 43 20 } g x=0
024 { 22 2 } GTO 2
025 { 33 } R⬇
026 { 20 } ×
027 { 33 } R⬇
028 { 20 } ×
029 { 44 40 0 } STO + 0
030 { 33 } R⬇
031 { 22 1 } GTO 1
032 { 42 21 2 } f LBL 2
033 { 45 0 } RCL 0
034 { 43 32 } g RTN
035 { 42 21 3 } f LBL 3
036 { 1 } 1
037 { 30 } −
038 { 43 13 } g LOG
039 { 43 44 } g INT
040 { 1 } 1
041 { 40 } +
042 { 13 } 10ˣ
043 { 43 32 } g RTN
Examples
3258 to base 3
325 ENTER
8 ENTER
3 A
21220.
11012 to base 8
1101 ENTER
2 ENTER
8 A
15.
Compared to your output, the original number and its conversion to decimal are missing.
But I am sure that you can modify this program according to your needs.
This is a mostly verbatim translation for the HP-41C:
Code:
01 LBL "BC"
02 STO 03
03 RDN
04 STO 01
05 ENTER^
06 XEQ 03
07 XEQ 00
08 RCL 03
09 XEQ 03
10 STO 01
11 RCL 03
12 LBL 00
13 STO 02
14 -
15 X<>Y
16 STO 00
17 LBL 01
18 RCL 01
19 X<>Y
20 RCL 02
21 /
22 INT
23 X=0?
24 GTO 02
25 RDN
26 *
27 RDN
28 *
29 ST+ 00
30 RDN
31 GTO 01
32 LBL 02
33 RCL 00
34 RTN
35 LBL 03
36 1
37 -
38 LOG
39 INT
40 1
41 +
42 10^X
43 END
And here's the same for the HP-42S:
Code:
00 { 58-Byte Prgm }
01▸LBL "BC"
02 STO 03
03 R↓
04 STO 01
05 ENTER
06 XEQ 03
07 XEQ 00
08 RCL 03
09 XEQ 03
10 STO 01
11 RCL 03
12▸LBL 00
13 STO 02
14 -
15 X<>Y
16 STO 00
17▸LBL 01
18 RCL 01
19 X<>Y
20 RCL 02
21 ÷
22 IP
23 X=0?
24 GTO 02
25 R↓
26 ×
27 R↓
28 ×
29 STO+ 00
30 R↓
31 GTO 01
32▸LBL 02
33 RCL 00
34 RTN
35▸LBL 03
36 1
37 -
38 LOG
39 IP
40 1
41 +
42 10↑X
43 END
|