06-22-2022, 09:35 PM

This code takes decimal inches, e.g., 14.25 in X and returns the following in Alpha:

Note: There's an old forum topic HP-41 Advantage Pac AIP function, anyone? that provides alternatives if AIP isn't available. In particular, Namir provides an equivalent to AIP for the CX.

The maximum denominator, which should be a power of 2, is assumed to be set in register 0. Note that the code rounds to the nearest fraction.

The code modifies flag 2 and registers 2 and 3.

Sample output (Reg 1=8, flag 1 clear):

EDIT: Based on comments from Xorand and Thomas Klemm, below, fixed the description to refer to the correct register and removed a couple of unnecessary bytes.

- feet inches-fractions if flag 1 is clear, e.g., 1' 2-1/4"
- inches-fractions if flag 1 is set, e.g., 14-1/4"

Note: There's an old forum topic HP-41 Advantage Pac AIP function, anyone? that provides alternatives if AIP isn't available. In particular, Namir provides an equivalent to AIP for the CX.

The maximum denominator, which should be a power of 2, is assumed to be set in register 0. Note that the code rounds to the nearest fraction.

The code modifies flag 2 and registers 2 and 3.

Sample output (Reg 1=8, flag 1 clear):

Code:

12.0000 1'

12.4900 1' 1/2"

1.0000 1"

1.2500 1-1/4"

14.0000 1' 2"

14.0626 1' 2-1/8"

14.3125 1' 2-3/8"

4.0010 4"

7.9990 8"

Code:

LBL "FIF"

CLA

CF 02

X<=0?

"-"

ABS

RCL 00

*

.5

+

INT

RCL 00

/

ENTER

FS? 01

GTO 00

INT

X=0?

GTO 01

12

/

INT

X=0?

GTO 01

AIP

39

XTOA

RDN

ᵀ" "

LBL 01

RDN

ENTER

ENTER

12

MOD

LBL 00

INT

X=0?

GTO 02

SF 02

AIP

LBL 02

RDN

FRC

X=0?

GTO 05

FS? 02

ᵀ"-"

SF 02

RCL 00

*

STO 01

RCL 00

STO 02

LBL 03

RCL 01

2

MOD

X>0?

GTO 04

2

ST/ 01

ST/ 02

GTO 03

LBL 04

RCL 01

AIP

ᵀ"/"

RCL 02

AIP

LBL 05

34

FS? 02

XTOA

AVIEW

END

EDIT: Based on comments from Xorand and Thomas Klemm, below, fixed the description to refer to the correct register and removed a couple of unnecessary bytes.