HP Forums
number base conversion for hp17b/17bii - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: number base conversion for hp17b/17bii (/thread-1660.html)



number base conversion for hp17b/17bii - Don Shepherd - 06-18-2014 06:53 PM

OK, you've got your old 17b or 17bii you use for all your financial needs, but now you need something to do number base conversions. There is no need to go to a scientific model, the solver is your friend.

B1 = old base (2-10)
B2 = new base (2-10)
N = number to convert
ANS = solve for this

Either B1 or B2 must be 10.

BC:ANS=\(\Sigma\)(I:0:LOG(N)\(\div\)LOG(B2):1:MOD(N:B2)\(\times\)B1I+0\(\times\)L(N:IDIV(N:B2))​)


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-19-2014 01:59 AM

(06-18-2014 06:53 PM)Don Shepherd Wrote:  BC:ANS=\(\Sigma\)(I:0:LOG(N)\(\div\)LOG(B2):1:MOD(N:B2)\(\times\)B1I+0\(\times\)L(N:IDIV(N:B2))​)

Very cool! Thanks for consistently bringing up this calculator.
You don't need MOD if you combine the calculations from successive lines.

Example: DEC → OCT
Code:
         2014
+   2 *   251
+  20 *    31
+ 200 *     3
         ----
         3736

BC:ANS=
0\(\times\)L(K:FROM-TO)
+N
+\(\Sigma\)(I:1:LOG(N)\(\div\)LOG(TO):1:
  G(K)\(\times\)L(N:IDIV(N:TO))
  +0\(\times\)L(K:FROM\(\times\)G(K))
​)


Kind regards
Thomas


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-19-2014 09:06 AM

A little shorter:

BC:ANS=
N+
(FROM-TO)\(\times\)
\(\Sigma\)(I:0:LOG(N)\(\div\)LOG(TO):1:
  L(N:IDIV(N:TO))\(\times\)FROM^I
​)



RE: number base conversion for hp17b/17bii - Don Shepherd - 06-19-2014 01:45 PM

(06-19-2014 09:06 AM)Thomas Klemm Wrote:  A little shorter:

BC:ANS=
N+
(FROM-TO)\(\times\)
\(\Sigma\)(I:0:LOG(N)\(\div\)LOG(TO):1:
  L(N:IDIV(N:TO))\(\times\)FROM^I
​)

Thomas, that is way cool! Thanks.

The method I chose was based on how I learned to manually convert numbers from one base to another back in computer programming school in 1968. That method is described at the bottom of this page. I just converted those manual steps to an equivalent solver equation.

I like your method also, it is simple and elegant.

Don


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-19-2014 02:06 PM

(06-18-2014 06:53 PM)Don Shepherd Wrote:  Either B1 or B2 must be 10.

You could set either B1 or B2 to 100. This allows conversions between HEX and DEC.

Example: CAFEHEX
B1: 16
B2: 100
N: 12101514
ANS: 51,966



RE: number base conversion for hp17b/17bii - Don Shepherd - 06-19-2014 02:36 PM

(06-19-2014 02:06 PM)Thomas Klemm Wrote:  
(06-18-2014 06:53 PM)Don Shepherd Wrote:  Either B1 or B2 must be 10.

You could set either B1 or B2 to 100. This allows conversions between HEX and DEC.

Example: CAFEHEX
B1: 16
B2: 100
N: 12101514
ANS: 51,966

I am stunned! I never thought that was possible. You are a true missle-man.


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-19-2014 10:15 PM

(06-19-2014 02:36 PM)Don Shepherd Wrote:  I am stunned! I never thought that was possible.

It's been there for a while: Base Conversion for HP-11C


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-21-2014 10:18 PM

Here's a program for the HP-12C:
Code:
01 -       36  ENTER
02 -       36  ENTER
03 -    45 15  RCL FV
04 -       10  ÷
05 -    43 25  INTG
06 -    43 13  CFo
07 -    45 15  RCL FV
08 -       10  ÷
09 -    43 25  INTG
10 -    43 35  x=0
11 - 43,33 14  GTO 14
12 -    43 14  CFj
13 - 43,33 07  GTO 07
14 -       33  R↓
15 -        1  1
16 -    45 14  RCL PMT
17 -       22  1/x
18 -       24  Δ%
19 -    44 12  STO i
20 -       33  R↓
21 -       33  R↓
22 -    42 13  NPV
23 -    45 14  RCL PMT
24 -    45 15  RCL FV
25 -       30  −
26 -       20  ×
27 -       40  +

Example: 201410 → 37368
10 STO PMT
8 STO FV
2014 R/S



RE: number base conversion for hp17b/17bii - Don Shepherd - 06-21-2014 11:27 PM

(06-21-2014 10:18 PM)Thomas Klemm Wrote:  Here's a program for the HP-12C:
Code:
01 -       36  ENTER
02 -       36  ENTER
03 -    45 15  RCL FV
04 -       10  ÷
05 -    43 25  INTG
06 -    43 13  CFo
07 -    45 15  RCL FV
08 -       10  ÷
09 -    43 25  INTG
10 -    43 35  x=0
11 - 43,33 14  GTO 14
12 -    43 14  CFj
13 - 43,33 07  GTO 07
14 -       33  R↓
15 -        1  1
16 -    45 14  RCL PMT
17 -       22  1/x
18 -       24  Δ%
19 -    44 12  STO i
20 -       33  R↓
21 -       33  R↓
22 -    42 13  NPV
23 -    45 14  RCL PMT
24 -    45 15  RCL FV
25 -       30  −
26 -       20  ×
27 -       40  +

Example: 201410 → 37368
10 STO PMT
8 STO FV
2014 R/S

That is just amazing, Thomas. I'm sure the creators of NPV and delta-percent on the 12c never envisioned those functions being used for number base conversions.

I tip my hat to you, you are "da man".


RE: number base conversion for hp17b/17bii - Thomas Klemm - 06-21-2014 11:54 PM

But then I realized that the 1:1 translation of my HP-11C program was shorter. And it uses only 3 registers. However it was fun to figure it out.

Addendum:
As long as the from-base PMT doesn't change the following lines could be removed:
Code:
15 -        1  1
16 -    45 14  RCL PMT
17 -       22  1/x
18 -       24  Δ%
19 -    44 12  STO i
20 -       33  R↓
21 -       33  R↓
With this we are at the same number of lines.
Of course you still have to calculate i once and store it.

(06-21-2014 11:27 PM)Don Shepherd Wrote:  That is just amazing, Thomas. I'm sure the creators of NPV and delta-percent on the 12c never envisioned those functions being used for number base conversions.

I've seen this trick in Valentin's paper: HP-12C’s Serendipitous Solver