Showing posts with label DM32. Show all posts
Showing posts with label DM32. Show all posts

Saturday, August 16, 2025

RPN: HP 32S & DM42: Converting Real Numbers to Hexadecimal Approximations

RPN: HP 32S & DM42: Converting Real Numbers to Hexadecimal Approximations



Introduction


We know calculators that have base conversions easily convert integers to different bases. But what about all real numbers? Not so much. Today’s blog will tackle it.


The procedure given today should work for converting from decimal to octal, binary, and hexadecimal. I chose hexadecimal:


0.A B C D… _16

The digit A is in units of 1/16.

The digit B is in units of 1/16^2 or 1/256.

The digit C is in units of 1/16^3 or 1/4096.

The digit D is in units of 1/16^2 or 1/65536.

and so on.


Note: The procedure considers positive real numbers only.


Example: Convert 7.86 to hexadecimal using 4 places


In hexadecimal, 4 places translates to terms of 1/65536.


Separate 7.86 into its integer and fractional parts.

Integer Part: 7

Fractional Part: 0.86

Convert the fractional part to n parts of 65536. (16^4)*

0.86 * 65536 = 56360.96

Round n to the nearest integer. Use the formula: int(n + 0.5) = int(n + 1/2)

Int(56360.96 + 0.5) = 53361

(round(56360.96, 0) = 53361)

Convert both original integer part and the last result to hexadecimal.

Integer Part: 7_10 → 7_16

Frac in terms of 65536: 53361_10 → DC29_16

**If the fractional part has less than four* digits showing in the calculator, pad the converted part with zeros on the left.


The approximate answer reads as:

7.86_10 → 7.DC29_16

Recall in Hexadecimal:

A=10, B=11, C=12, D=13, E=14, F=15.


* precision: number of places.


HP 32S/HP 32SII/DM32 Code


H01 LBL H

H02 ENTER

H03 IP

H04 x<>y

H05 FP

H06 16

H07 4 (** - accuracy level, number of places)

H08 y^x

H09 ×

H10 2

H11 1/x

H12 +

H13 IP

H14 HEX

H15 STOP

H16 DEC

H17 RTN



HP 42S/DM42 Code


01 LBL “→HEX”

02 ENTER

03 IP

04 x<>y

05 FP

06 16

07 4 (** - accuracy level, number of places)

08 Y↑X

09 ×

10 0.5

11 +

12 IP

13 HEXM

14 STOP

15 EXITALL

16 RTN



When the program stops initially, the results are shown as follows:

Y: integer part

X: fractional part – right justified


Remember the number of places (precision) because if the fractional part has less digits, pad zeroes to the left.


Examples


n = precision = 4

Decimal

Y: Hex Integer

X: Hex Fractional (displayed)

Result (base 16)

3.5

3

8000

3.8000

π

3

243F

3.243F

√2

1

6A0A

1.6A0A

0.6732

0

AC57

0.AC57

0.0002

0

D

0.000D

e^4.1

3C

571D

3C.571D

8.2^1.7

23

C460

23.C460



Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


All posts are 100% generated by human effort.  The author does not use AI engines and never will.


Saturday, August 9, 2025

RPN: HP 15C and DM32: Integer Length and Digit Extraction

RPN: HP 15C and DM32: Integer Length and Digit Extraction (up to 99,999,999)



The following programs are utilities for positive integers:


(1) Integer Length: how many digits in a positive integer

(2) Digit Extraction: Get the nth digit of a positive integer


Note:  Do not use more than 8 digits (integers up to 99,999,999).   Beyond this, the program may return inaccurate answers.  

Thanks to J-F Garnier for pointing out the limitation of the programs.  


Integer Length


Find the number of digits of a positive integer. The integer is decimal base (base 10).


For a positive integer n, the number of the digits can be easily found by the formula:


L = int(log(x)) + 1



DM32, HP 32S, HP 32SII Code


L01 LBL L

L02 LOG

L03 IP

L04 1

L05 +

L06 RTN


HP 15C, DM15 Code


001

42, 21, 11

LBL A

002

43, 13

LOG

003

43, 44

INT

004

1

1

005

40

+

006

43, 32

RTN


The program finds the number of digits in the positive integer in the X stack.


Examples:


X = 436782; Length: 6

X = 5195008; Length: 7

X = 23156956; Length: 8


Digit Extraction


Extract the nth digit of a positive integer. Digit positions go from left to right. For example: for the integer 4582, the 1st digit is 4, the 2nd digit is 5, 3rd digit is 8, and 4th digit is 2.


Steps that this program follows:

Step 1: Find the length of the positive integer. L = int(log(x)) + 1.

Step 2: Divide X by 10^(L – n + 1). D = X / (10^(L – n + 1))

Step 3: Extract the fractional part. D = frac(D)

Step 4: Multiple the result by 10 and extract the integer part. D = int(10 * D)


Setting up the stack:

Y: integer

X: nth digit to extract


Variables Used:

DM32, HP 32S, HP 32S II

HP 15C, DM15

X

R1

N

R2

L

R3



DM32, HP 32S, HP 32SII Code


E01 LBL E

E02 STO N

E03 R↓

E04 STO X

E05 LOG

E06 IP

E07 1

E08 +

E09 STO L

E10 RCL X

E11 RCL L

E12 RCL- N

E13 1

E14 +

E15 10^x

E16 ÷

E17 FP

E18 10

E19 ×

E20 IP

E21 RTN


HP 15C, DM15 Code


001

42, 21, 12

LBL B

002

44, 2

STO 2

003

33

R↓

004

44, 1

STO 1

005

43, 13

LOG

006

43, 44

INT

007

1

1

008

40

+

009

44, 3

STO 3

010

45, 1

RCL 1

011

45, 3

RCL 3

012

45, 30, 2

RCL- 2

013

1

1

014

40

+

015

13

10^x

016

10

÷

017

42, 44

FRAC

018

1

1

019

0

0

020

20

×

021

43, 44

INT

022

43, 32

RTN


Examples


Integers

Length

2nd Digit

4th Digit

5th Digit

436782

6

3

7

8

5195008

7

1

5

0

23156956

8

3

5

6



Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


All posts are 100% generated by human effort.  The author does not use AI engines and never will.


Saturday, June 14, 2025

RPN With DM32: Interest Conversions

RPN With DM32: Interest Conversions



Today’s edition of RPN will focus on the Swiss Micros DM32 and HP 32SII calculator family (32SII, 33s 35s). My plan is to expand the range of calculators used in the RPN series to include the HP 41C/DM41X, HP 42S/DM42(n), HP 11C in addition to the HP 32SII and HP 15C families.



Nominal Interest Rate (EFF/NOM) and Effective Interest Rate (EFF)


When loans, annuities, mortgage, and other time-valued financial instruments are executed, the interest rate typically given is known as the nominal interest rate (NOM), also known as the APR. In mortgages and auto loans where the payments typically take place every month (12 per year), the periodic interest rate is divided by 12 to come up with the periodic rate. The periodic rate is compounded every month.


For example, if a loan has an APR (nominal rate, NOM) of 6% and payments take place monthly, the periodic interest rate is:


6% / 12 = 0.5%


The effective interest (EFF) rate is the nominal interest rate calculated as if was compounded annually.


Paid in Arrears


Typically, payments are paid in arrears, meaning payments are made after the service or the use of associated goods were provided. An example is the mortgage payment for the month of June is paid in the beginning of July.


The effective rate for payments paid in arrears is:


EFF% = (1 + NOM% / PY) ^ PY - 1


EFF%: effective interest rate

NOM%: nominal interest rate, APR

PY: payments per year


The effective rate for a APR of 6%, compounded monthly, paid in arrears is:


EFF% = (1 + 6% / 12) ^ 12 – 1 = (1 + 0.06 / 12)^12 – 1 ≈ 0.06168 (6.168%)



Paid in Advance


Sometimes, payments are paid in advance, where payments are made before the service or use of associated goods are provided. For example, the mortgage payment for the month of June is paid at the beginning of June or the end of May. The mortgage is paid in advance.


The effective rate for payments paid in arrears is:


EFF% = (1 - NOM% / PY) ^ (-PY) - 1


EFF%: effective interest rate

NOM%: nominal interest rate, APR

PY: payments per year


The effective rate for a APR of 6%, compounded monthly, paid in advance is:


EFF% = (1 - 6% / 12) ^ (-12) – 1 = (1 - 0.06 / 12)^(-12) – 1 ≈ 0.06200 (6.2%)



Conversion Formulas


The conversion formulas are (see source):

Payments in Arrears


EFF% = (1 + NOM% / PY) ^ PY – 1

NOM% = PY * ((1 + EFF%) ^ (1 / PY) – 1)


Payments in Advance


EFF% = (1 – NOM% / PY) ^ (-PY) – 1

NOM% = PY * (1 – (1 + EFF%)^(-PY))



DM32: Two Ways to Solve


There are two approaches to converting interest rates: directly through a program and using the solver.


Direct Programs


LBL A: NOM to EFF, Payments in Arrears


LBL A
STO Z
÷
1
x<>y
%
+
RCL Z
y^x
1
-
2
10^x
×
RTN


Syntax:

Y: NOM

X: PY

XEQ A


(Y: 5, X: 12, XEQ A: 5.11619)



LBL B: NOM to EFF, Payment in Advance


LBL B
STO Z
÷
1
x<>y
%
-
RCL Z
+/-
y^x
1
-
2
10^x
×
RTN


Syntax:

Y: NOM

X: PY

XEQ B


(Y: 5, X: 12, XEQ B: 5.13809)



LBL C: EFF to NOM, Payments in Arrears


LBL C
STO Z
1/x
x<>y
1
x<>y
%
+
x<>y
y^x
1
-
RCL× Z
2
10^x
×
RTN


Syntax:

Y: EFF

X: PY

XEQ C


(Y: 5, X: 12, XEQ C: 4.88895)



LBL D: EFF to NOM, Payment in Advance


LBL D
STO Z
1/x
+/-
x<>y
1
x<>y
%
+
x<>y
y^x
1
x<>y
-
RCL× Z
2
10^x
×
RTN


Syntax:

Y: EFF

X: PY

XEQ D


(Y: 5, X: 12, XEQ D: 4.86911)



Using The Solver


The DM32, and by extension, the HP 32SII, HP 33s, and HP 35s, has a solver that can solve for any variable. The solver uses a program in the format:


LBL α

INPUT (var)

INPUT (var)

function(var) = 0

RTN


To solve the equation (DM32, HP 32SII):


1. Press [ blue shift/right shift ] [ XEQ ] (FN=). An FN= prompt appears asking for a label.

2. Press [ blue shift/right shift ] [ 7 ] (SOLVE). You will be prompted to enter the variable to be solved.

3. The calculator prompts for values for any of the values. Press [ R/S ] to accept.

4. The solution is shown. I think the values and solutions are stored in the solutions. It is the case for the DM32, HP 32SII, and HP 32S.


Notes:

* HP 32S has the FN= and SOLVE in the SOLVE/∫ menu ([orange shift ] [ 1 ]).

* The right shift turned lavender in later HP 32SII calculators (late 1990s/early 2000s).


LBL S: Solver

LBL S
INPUT E
INPUT M
INPUT N
1
RCL M
RCL÷ N
+
RCL N
y^x
1
-
RCL- E
RTN


The equation is:

E = (1 + M/N) ^ N – 1


E = EFF%

M = NOM% (or APR%)

N = payments per year


The EFF% and NOM% must be entered in decimal. For payments in arrears, enter N as positive. For payments in advance, enter N as negative.


Example


Set function as:


FN= S

NOM to EFF, pmts in arrears


Solve E


M = 5% = 0.05

N = 12


E = 0.05116

(5.116%)

NOM to EFF, pmts in advance


Solve E


M = 5% = 0.05

N = -12


E = 0.05138

(5.138%)

EFF to NOM,

pmts in arrears


Solve M


E = 5% = 0.05

N = 12


M = 0.04889

(4.889%)

EFF to NOM,

pmts in advance


Solve M


E = 5% = 0.05

N = -12


M = 0.04869

(4.869%)


Source


J.J. Rose and E.M. Reeves VALPAC: A Discounted Cash Flow Approach To Property Valuation. (user manual) The Incorporated Society of Valuers and Auctioneers. An HP 41C Pac.


Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Basic vs. Python: Circle Inscribed in Circle [HP 71B, Casio fx-CG 100]

Basic vs. Python: Circle Inscribed in Circle Calculators Used: Basic: HP 71B Python: Casio fx-CG 100 Introduction ...