Thursday, July 14, 2016

HP 12C Programming Part I: Modulus, GCD, PITI

HP 12C Programming Part I:  Modulus, GCD, PITI 

The last stop (for now) on my 1980s tour is the Hewlett Packard HP 12C calculator, one of the most popular financial calculators of all time.  The HP 12C was first manufactured in 1982 and has been seen ever since.

Today, there are two versions of the HP 12C:  the original and the Platinum.  The original is RPN only and has 99 programming steps of memory.  The Platinum edition, first released in 2003, has room for 400 steps and includes Algebraic mode.

In this series, I'll concentrate on the 1982 classic.  Albeit, using one manufactured this decade, the processing speed in today's HP 12C's compared to those produced in the 1980s is tremendous.


HP 12C Modulus

This program takes the modulus of two numbers:
Y MOD X = X * FRAC(Y/X)
In this program, X > 0 and Y > 0.

STEP
CODE
KEY
01
10
÷
02
43, 36
LST x
03
34
X<>Y
04
43, 24
FRAC
05
20
*
06
43, 33, 00
GTO 00

Input:  Y [ENTER] X [R/S],  
Result:  Y MOD X

Test 1:  124 MOD 77  = 47
Test 2: 3862 MOD 108 = 82

HP 12C Greatest Common Divisor (GCD)

This program calculates the greatest common divisor of two integers.  You can enter the two integers in either order.

Program:
STEP
CODE
KEY
COMMENT
01
43, 34
X≤Y
Determine which integer is greater
02
34
X<>Y

03
44, 1
STO 1
R1 = max(X,Y)
04
34
X<>Y

05
44, 0
STO 0
R0 = min(X,Y)
06
45, 1
RCL 1
Begin Euclidian division routine
07
45, 1
RCL 1
Recall R1 twice
08
45, 0
RCL 0

09
10
÷

10
43, 25
INTG

11
45, 0
RCL 0

12
20
*

13
30
-

14
43, 35
X=0

15
43, 33, 21
GTO 21

16
34
X<>Y

17
44, 1
STO 1

18
34
X<>Y

19
44, 0
STO 0

20
43, 33, 06
GTO 06

21
45, 0
RCL 0

22
43, 33, 00
GTO 00



Input:  integer [ENTER] integer [R/S]
Result: GCD

Test 1:   GCD(142,25)
Input:  142 [ENTER] 25 [R/S]
Result: 1

Test 2:  GCD(2555, 1365).   Result: 35

HP 12 PITI (Principal, Interest, Taxes, Insurance)

Here is a simple program that calculates the payment (principal and interest) while taking property taxes and insurance in consideration.  Property taxes and insurance are assumed to be combined as an annual amount.  Payments are assumed to be on a monthly basis.

Program:
STEP
CODE
KEY
COMMENT
01
1
1

02
2
2

03
10
÷
(tax + ins)/12
04
44, 0
STO 0

05
14
PMT

06
14
PMT
Need to press PMT twice.  Second press calculates payment.
07
45, 0
RCL 0

08
16
CHS

09
40
+
PITI is assumed to be an outflow
10
43, 33, 00
GTO 00
Ends the program

Input:
Number of Years [ g ] [ n ] (12*)
Annual Interest Rate [ g ] [ i ] (12÷)
Loan Amount [PV]
Annual Property Insurance and Taxes [R/S]
Result:  PITI

Test:  Calculate PITI for a 30-year loan of $205,000.  The rate on the loan is 4.1%.  Annual insurance and property taxes are estimated to be $1,102.50.
Input:  30 [ g ] [ n ] (12*), 4.1 [ g ] [ i ] (12÷), 205000 [PV], 1102.50 [R/S]
Result:  -1,082.43  (PITI = $1,082.43)

This is blog is proerpty of Edward Shore, 2016.




Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...