Showing posts with label HP 32Sii. Show all posts
Showing posts with label HP 32Sii. Show all posts

Saturday, September 13, 2025

RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric)



The Stopping Sight Distance Formula – Derivation


The stopping sight distance (SSD) formula calculates the theoretical distance that a driver needs to see to react and stop to avoid colliding with a person or hazard safely.


The SSD is measured in meters (or in US units, feet). This blog entry will focus on the SI system (meters, kilograms, seconds).


The SSD is broken down into two parts:


SSD = d1 + d2


Part 1: d1: Reaction Distance


d1 = reaction distance = v * t

v = velocity of the vehicle

t = reaction time that the driver takes to hit their brakes. The ideal reaction time is 1 second (or less). However, if the driver is tired or is later in age, the reaction time will increase. Typically, the reaction time is assumed to be 2.5 seconds.


In calculating SSD, the velocity is entered in usually in km/hr. (kilometers per hour). We need to change this into m/s.


1 km / hr * 1,000 m / 1 km * 1 hr / 3,600 s = 1,000 / 3,600 m/s = 5 / 18 m/s


Note many publication rounds this conversion factor to 0.278.


Hence, the completed reaction distance portion is:


d1 = 5 / 18 * v * t



Part 2: d2: Stopping Distance


This part is more complicated and includes factors such as friction force (µ), weight of the car (mass/g, g = 9.80665 m/s^2), and grade of the road (grd%, which is the increase or decrease of the slope of the road).


A common formula for d2 is:

d2 = v^2 / (a * (µ + grd%))


Another way to determine d2 is to equate the kinetic energy of the car with the work required to stop the car:


KE = work

m * v^2 / 2 = (µ + grd%) * w * d2


where:

m = mass of the car, in kg

v = velocity of the car, in km/hr

µ = friction factor (unit-less)

d2 = distance in m

w = weight of the car in N

grd% = grade of the road, in decimal (i.e. 1% = 0.01) (unit-less)

g = 9.80665 m/s^2


Note that mass = weight / gravity acceleration; m = w / g:


w / g * v^2 / 2 = (µ + grd%) * w * d2


Solving for d2:


d2 = v^2 / (2 * g * µ) = v^2 / (2 * g) * 1 / (µ * grd%)



Note that d2 is in meters. But v is in km/hr. Once again, a conversion factor is required. I’m focusing on the portion v^2 / (2 * g). I’m going to break the problem down into two parts: numerator and denominator.


Numerator:


1 km^2 / hr^2 * 1^2 hr^2 / 3,600^2 s^2 * 1,000^2 m^2 / 1^2 km^2 = 25 / 324 m^2 / s^2


Denominator:


2 * g = 2 * 9.80665 m/s^2 = 19.6133 m/s^2


Numerator/Denominator:


(25 / 324 m^2/s^2) / 19.6133 m/s^2 ≈ 3.934090328 * 10^-3 m ≈ 1/254.188368 m


Publications and associations, such as the AASHTO (American Association of State Highway and Transportation Officials), will often round 254.188368 to 254.



The Completed Formula


SSD = d1 + d2 = d1 = 5/18 * v * t + v^2 / (254.188368 * (µ + grd%))


The value of µ usually takes the values between 0.3 and 0.4. For the program, I’m assuming that µ = 0.35 for wet road conditions and µ = 0.70 dry conditions



SSD in US Units


Using similar analysis, the SSD in US units is:


SSD = 22/15 * v * t + v^2 / (29.91388812 * (µ +grd%))


where: v = velocity in mi/hr (mph), t = reaction time in seconds, SSD in feet (ft)


Publications will round the constants to 1.47 and 30, respectively.


On obtaining the conversion factors, note that:

1 mi/hr = 22/15 ft/s

1 mi^2/hr^2 = 484/225 ft^2/s^2

2 * g = 2 * 9.80665 m/s^2 * 100/30.48 ft/s^2 ≈ 2 * 32.17404856 ft/s^2 ≈ 64.34809711 ft/s^2

(484/225) / (64.38409711) ≈ 0.033429288 ≈ 1/29.91388812



DM32/ HP 32II Program: Stopping Sight Distance (SI Units)

(not for the HP 32S because it uses messages)


D01 LBL D

D02 35 [store constants; wet conditions times 100]

D03 STO A

D04 70 [store constants; dry conditions times 100]

D05 STO B

D06 2.5 [store default reaction time]

D07 STO T

D08 INPUT T

D09 INPUT V

D10 INPUT G [enter grade as a percentage: 1% → 1]

D11 SF 10 [set message mode, SF, decimal point, 0]

D12 “1 WET 2 DRY”

D13 INPUT i [input indirect variable]

D14 CF 10 [turn off message mode, CF, decimal point, 0]

D15 RCL V

D16 x^2

D17 RCL (i)

D18 RCL+ G

D19 100

D20 ÷

D21 254.188368

D22 ×

D23 ÷

D24 5

D25 RCL× V

D26 RCL× T

D27 18

D28 ÷

D29 +

D30 STO D [store and view SSD]

D31 VIEW D

D32 RTN


HP 42S/DM42/Free 42 Program: Stopping Sight Distance (SI Units)

(This program is similar to the 32SII version.)


00 {121-Byte Program}

01 LBL “SSD”

02 35

03 STO 01

04 70

05 STO 02

06 2.5

07 STO 03

08 “REACT TIME?”

09 PROMPT

10 STO 03

11 RCL 04

12 “VELOCITY?”

13 PROMPT

14 STO 04

15 RCL 05

16 “GRADE?”

17 PROMPT

18 STO 05

19 RCL 00

20 “1. WET 2. DRY”

21 PROMPT

22 STO 00

23 RCL 04

24 X↑2

25 RCL IND 00

26 RCL+ 05

27 100

28 ÷

29 254.188368

30 ×

31 ÷

32 5

33 RCL× 03

34 RCL× 04

35 18

36 ÷

37 +

38 STO 06

39 “SSD=”

40 ARCL ST X

41 RTN



Variables:

R00 = choice variable

R01 = wet condition friction coefficient * 100

R02 = dry condition friction coefficient * 100

R03 = reaction distance (set to default as of 2.5 sec)

R04 = velocity (km/hr)

R05 = grade

R06 = SSD in meters


Examples


Velocity: 96.5606 km/hr (about 60 mi/hr), Time: 2.5 seconds, Grade: 0%

Dry Conditions (i = 2): SSD: 119.4578 m

Wet Conditions (i = 1, µ = 0.35), SSD: 171.8596 m


Velocity: 96.5606 km/hr, Time: 1.5 seconds, Dry Road

Grade: +1%: SSD: 91.8973 m

Grade: -1%: SSD: 93.3948 m



Sources


American Association of State Highway and Transportation Officials NCHRP Report 400. 1997. Last accessed April 27, 2025. https://onlinepubs.trb.org/onlinepubs/nchrp/nchrp_rpt_400.pdf


Chandra, Satish IITR “Stopping Sight Distance on a road. Definition, concept, and evaluation of SSD with examples.” YouTube Video. July 16, 2023. https://www.youtube.com/watch?v=HEzdJE7NQeU&t=973s Last accessed April 27, 2025.


Omni Calculator. “Stopping Distance Calculator” July 22, 2024. Last accessed April 26, 2025. https://www.omnicalculator.com/physics/stopping-distance



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.

The author does not use AI engines and never will.

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.


RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...