Showing posts with label HP 42S. Show all posts
Showing posts with label HP 42S. 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, April 12, 2025

RPN with HP 15C & DM32: Stack Register Arithmetic

RPN with HP 15C & DM32: Stack Register Arithmetic


Got a treat for today folks. First...


14 YEARS!!


On the 16th, it will be 14 years since my blog started!!!! Thank you so much for your support – the blog is one of my joys of life.


Today is another installment of RPN with HP 15C & DM32, I hope you are enjoying this new monthly series, currently every second Saturday of the month.



Stack Register Arithmetic


As we know, nearly all Hewlett Packard (HP) and I think all Swiss Micros (SM) calculators that operate on Reverse Polish Notation (RPN) or Reverse Polish Lisp (RPL, think HP 48 and 50g), a feature that we can calculate an arithmetic operation (+, -, ÷, ×) directly on any number stored in any memory register. It’s a very handy feature indeed.


On the HP 41C, DM41, HP 42S, and DM42 series of calculators, that ability extend to the stack registers themselves (X, Y, Z, T, L (LastX)). To do this, press [ STO ], the required arithmetic operation, the decimal point [ . ], and the appropriate key.


Example:


The current stack is set as:


T: 11

Z: 16

Y: 10

X: 5


Note the 5 in the X stack. We can use the contents of the X stack to do operations on the other levels without “disturbing” the other levels.


Add 5 to stack Z without having to disturb the stack. ST+ Z (41), STO+ ST Z (42) returns:


T: 11

Z: 21

Y: 10

X: 5


Note that the entire stack except Z remains the same.


Multiply stack T by 5. 5 is in the X stack already. ST* T (41), STO× ST T (42) returns:


T: 55

Z: 21

Y: 10

X: 5


Pretty neat, right?


In summary:


STO+ SL: new SLV= old SLV + X

STO- SL: new SLV = old SLV – X

STO× SL: new SLV = old SLV × X

STO÷ SL: new SLV = old SLV ÷ X


where:

X = value in stack level X (display on one-line calculators)

SLV = stack value level (X, Y, Z, T, L)


The 15C and 32S series do not have a native way to do this, but today I will present a way to mimic these powerful stack storage arithmetic on levels X, Y, Z, and T. Most of them will not require the use of an outside memory register (i.e. R0 or R1 for the 15C series, or A or Z for the 32S series).


These techniques were tested on a Hewlett Packard HP 15C and Swiss Micros DM32. They probably would work on the HP 12C (or equivalent) as well, just substitute the roll up (R↑) with three roll down (R↓ R↓ R↓) commands when encountered.


FYI, the 42 series also has recall arithmetic on stack levels, which returns on stack X.



The Algorithms


For the following algorithms, let {OP} stand for the arithmetic operation (+, -, ×, ÷). Let the hash symbol, {#}, stack for a register of your choice (i.e. R0 for 15 or A for 32).


Storage Arithmetic on Stack X


R↑

STO {#}

R↓

ENTER

{OP}

RCL {#}

R↓




Stack Illustration with STO+ X (it will be similar with the rest of the arithmetic operations)


t

z

z

t

z

z

z

t

z

y

y

z

y

z

y

z

y

x

x

y

x

y

x + x

y

x

t

t

x

x

x + x

t

x + x

START

R↑

STO {#}

R↓

ENTER

+

RCL {#}

R↓


Shortcuts:

STO- X: Clx

STO× X: x^2 (specifically, the square function)


The next set will not require a separate memory register.


Example:


40

30

30

40

30

30

30

40

30

20

20

30

20

30

20

30

20

10

10

20

10

20

20

20

10

40

40

10

10

10 + 10 = 20

40

20

START

R↑

STO {#}

R↓

ENTER

+

RCL {#}

R↓





Storage Arithmetic on Stack Y


This is by far the easiest.


{OP}

LAST X


Stack Illustration with STO+ Y (it will be similar with the rest of the arithmetic operations)


t

t

t

z

t

z

y

z

y + x

x

y + x

x

START

+

LAST X



Example:


40

40

40

30

40

30

20

30

30

10

20 + 10 = 30

10

START

+

LAST X




Storage Arithmetic on Stack Z


x<>y

R↓

{OP}

LAST X

R↑

x<>y


Stack Illustration with STO+ Z (it will be similar with the rest of the arithmetic operations)


t

t

y

y

y

t

t

z

z

t

y

t

z +x

z + x

y

x

z

t

z + x

x

y

x

y

x

z + x

x

y

x

START

x<>y

R↓

+

LAST X

R↑

x<>y



Example:


40

40

20

20

20

40

40

30

30

40

20

40

40

40

20

10

30

40

40

10

20

10

20

10

30 + 10 = 40

10

20

10

START

x<>y

R↓

+

LAST X

R↑

x<>y




Storage Arithmetic on Stack T


R↑

x<>y

{OP}

LAST X

x<>y

R↓



Stack Illustration with STO+ T (it will be similar with the rest of the arithmetic operations)


t

z

z

z

z

z

t + x

z

y

y

z

y

y

z

y

x

t

y

t + x

x

y

x

t

x

t + x

x

t + x

x

START

R↑

x<>y

+

LAST X

x<>y

R↓


Example:


40

30

30

30

30

30

50

30

20

20

30

20

20

30

20

10

40

20

50

10

20

10

40

10

40 + 10 = 50

10

50

10

START

R↑

x<>y

+

LAST X

x<>y

R↓



Until next time,


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.


Casio fx-991CW: Editing Variables

Casio fx-991CW: Editing Variables Introduction The newer set of Casio scientific calculators, better known as the Classwiz series, rev...