(12C) Base Conversion
08-25-2018, 02:32 PM
Post: #1
 Thomas Klemm Senior Member Posts: 1,885 Joined: Dec 2013
(12C) Base Conversion
This program is a slightly shorter version of the 2nd solution that uses the function NPV:
Code:
01 -    44 13  STO PV 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 -    45 14  RCL PMT 15 -        1  1 16 -       24  Δ% 17 -    44 12  STO i 18 -    45 13  RCL PV 19 -    42 13  NPV 20 -    45 14  RCL PMT 21 -    45 15  RCL FV 22 -       30  − 23 -       20  × 24 -       40  +

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

Formulas Used

Net Present Value

NPV = net present value of a discounted cash flow.
CFj = cash flow at period j.

$$NPV=CF_0+\frac{CF_1}{(1+i)^1}+\frac{CF_2}{(1+i)^2}+\cdots+\frac{CF_n}{(1+i)^n}​$$

Percentage

$$\Delta\%=100\ \frac{x-y}{y}$$

Explanation

We can calculate the remainders by dividing the number continuously by the base we want to transform to (here stored in FV):
Code:
2014 ÷ 8 = 251  →  6 = 2014 - 8 × 251  251 ÷ 8 =  31  →  3 =  251 - 8 ×  31   31 ÷ 8 =   3  →  7 =   31 - 8 ×   3    3 ÷ 8 =   0  →  3 =    3 - 8 ×   0

These remainders have to be multiplied by powers of the base we transform from (here stored in PMT):
Code:
   6 = 1 × 2014 - 8 × 1 ×  251   30 = 10 × 251 - 8 × 10 ×  31  700 = 100 × 31 - 8 × 100 ×  3 3000 = 1000 × 3 - 8 × 1000 × 0

And then when we add up all the terms we get:
Code:
3736 = 2014 + 2 × (251 + 10 × 31 + 100 × 3)

To calculate the polynomial we use NPV.

For this to work we have to solve for $$i$$ in:

$$1+\frac{i}{100}=\frac{1}{b}$$

where $$b$$ is the base we transform from.

Thus

\begin{align*} i &= 100\ (\frac{1}{b}-1)\\ &= 100\ \frac{1-b}{b} \end{align*}

That's why we can use the $$\Delta\%$$ function to calculate $$i$$:
Code:
14 -    45 14  RCL PMT 15 -        1  1 16 -       24  Δ% 17 -    44 12  STO i

I was a bit surprised that ENTER is needed here:
Code:
01 -    44 13  STO PV 02 -       36  ENTER 03 -    45 15  RCL FV

But it appears that STO PV disables the stack lift.

From the manual:
Quote:In addition, the stack does not lift when a number is entered if the last operation performed was storing a number into a financial register.
 « Next Oldest | Next Newest »

 Messages In This Thread (12C) Base Conversion - Thomas Klemm - 08-25-2018 02:32 PM RE: (12C) Base Conversion - rprosperi - 08-25-2018, 05:28 PM RE: (12C) Base Conversion - Albert Chan - 08-25-2018, 06:38 PM RE: (12C) Base Conversion - Dieter - 08-25-2018, 08:38 PM RE: (12C) Base Conversion - rprosperi - 08-25-2018, 09:02 PM RE: (12C) Base Conversion - Albert Chan - 08-25-2018, 11:06 PM RE: (12C) Base Conversion - Thomas Klemm - 08-25-2018, 08:30 PM RE: (12C) Base Conversion - Thomas Klemm - 08-27-2018, 08:29 PM

User(s) browsing this thread: 1 Guest(s)