Overview
-2 programs are listed below:
-The first one only deals with ( positive ) integers and bases b <
101
If 10 < b < 101, each "digit" is represented by
2 decimal digits from the decimal point:
For instance N = 1A2EF ( base 16 ) must be keyed in
110021415 ( N = 107247 in decimal )
-The second program also deals with ( positive ) fractional arguments
If 10 < b < 101, each "digit"
is represented by 2 decimal digits from the decimal point
If 100 < b < 1001, each "digit" is represented by 3 decimal
digits from the decimal point ... and so on ...
For instance, in base 234, R = 5,233,001.122,
is a number with 3 "digits" in its integer part ( 5 233 1 )
and 1 "digit" in its fractional part ( 122 )
( in decimal, R = 328303.5214 )
-Roundoff errors are often unavoidable for fractional numbers
Integer Arguments and b < 101
Data Registers: /
Flags: /
Subroutines: /
01 LBL "b-X"
02 10 03 X<Y? 04 X^2 05 STO T 06 CLX 07 STO M 08 SIGN 09 X<> Z 10 LBL 01 11 R^ 12 ST/ Y |
13 RDN
14 FRC 15 ST- L 16 R^ 17 ST* Y 18 X<> T 19 ST* Y 20 X<> Z 21 ST* Z 22 X<>Y 23 ST+ M 24 X<> L |
25 X#0?
26 GTO 01 27 X<> M 28 RTN 29 LBL "X-b" 30 SIGN 31 0 32 LASTX 33 R^ 34 LBL 02 35 STO M 36 X<>Y |
37 MOD
38 ST- M 39 X<> L 40 ST/ M 41 RCL M 42 X<>Y 43 R^ 44 ST* L 45 X<> L 46 ST+ T 47 CLX 48 10 |
49 X<Y?
50 ST* X 51 ST* L 52 X<> L 53 RDN 54 X<>Y 55 X#0? 56 GTO 02 57 STO M 58 X<> Z 59 END |
( 103 bytes / SIZE 000 )
1-Base b >>> Base 10 ( LBL "b-X" )
STACK | INPUTS | OUTPUTS |
Y | Nb | b |
X | b | N10 |
2-Base 10 >>> Base b ( LBL "X-b" )
STACK | INPUTS | OUTPUTS |
Y | N10 | b |
X | b | Nb |
Example1: Convert (1234)7
to the decimal scale and then to the nonary scale
1234 ENTER^
7 XEQ "b-X"
>>> 466
9 XEQ "X-b" ( or simply R/S ) >>> 567
whence (1234)7 = 466 =
(567)9
Example2: Convert (16267)12 to the decimal scale and then to the hexadecimal scale and the septenary scale.
106020607 ENTER^
12 XEQ "b-X" >>> 31471
16 R/S yields 7101415 whence
(16267)12 = 31471 = (7AEF)16
-Similarly, 31471 ENTER^ 7
XEQ "X-b" gives 160516 whence
(16267)12 = (160516)7
Fractional Arguments
Data Registers: /
Flags: /
Subroutines: /
-Line 72 = synthetic STO P
01 LBL "B-X"
02 CLA 03 ENTER^ 04 DSE X 05 LOG 06 INT 07 1 08 + 09 STO N 10 X<> Z 11 ENTER^ 12 LOG 13 RCL N 14 / 15 E2 16 + 17 INT 18 E2 19 - 20 R^ |
21 X<>Y
22 Y^X 23 STO Z 24 CLX 25 RCL N 26 ST* L 27 X<> L 28 10^X 29 / 30 LBL 01 31 ENTER^ 32 INT 33 ST- Y 34 X<> Z 35 ST* Z 36 X<> Z 37 ST+ M 38 R^ 39 ST/ T 40 RDN |
41 CLX
42 RCL N 43 10^X 44 * 45 X#0? 46 GTO 01 47 X<> M 48 CLA 49 RTN 50 LBL "X-B" 51 CLA 52 ENTER^ 53 DSE X 54 LOG 55 INT 56 1 57 + 58 STO N 59 STO O 60 CLX |
61 RCL Z
62 LOG 63 RCL Y 64 LOG 65 / 66 INT 67 2 68 + 69 ST* O 70 CLX 71 11 72 STO P 73 RDN 74 LBL 02 75 RCL N 76 ST- O 77 RCL O 78 X<>Y 79 / 80 RCL Y |
81 X<>Y
82 Y^X 83 RDN 84 X<> T 85 MOD 86 ST- Y 87 X<>Y 88 LASTX 89 / 90 RCL O 91 10^X 92 * 93 ST+ M 94 X<> Z 95 DSE P 96 GTO 02 97 RCL M 98 CLA 99 END |
( 152 bytes / SIZE 000 )
1-Base B >>> Base 10 ( LBL "B-X" )
STACK | INPUTS | OUTPUTS |
Y | Nb | b |
X | b | N10 |
2-Base 10 >>> Base B ( LBL "X-B" )
STACK | INPUTS | OUTPUTS |
Y | N10 | b |
X | b | Nb |
Example1: Convert (12.34)7
to the decimal scale and then to the nonary scale
12.34 ENTER^
7 XEQ "B-X"
>>> 9.510204082
9 XEQ "X-B"
( or simply R/S ) >>> 10.45284032
whence (12.34)7 = 9.510204082 = (10.45284032)9
Example2: Convert (4,123.092,046)128 to the decimal scale and then to the scale B = 41
4,123.092,046 ENTER^
128
XEQ "B-X" >>> 635.7215576
41 R/S
>>> 15,20.29,23,38
whence
(4,123.092,046)128 = 635.7215576
= (15,20.29,23,38)41
References:
[1] Abramowitz and Stegun , "Handbook of Mathematical Functions"
- Dover Publications - ISBN 0-486-61272-4
[2] Philippe Descamps & Jean-Jacques Dhenin , "Programmer
HP-41" - PSI - ISBN 2-86595-056-5 ( in French )