(41CX w/Advantage Pac) Feet inches fractions - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Software Libraries ( /forum-10.html)+--- Forum: HP-41C Software Library ( /forum-11.html)+--- Thread: (41CX w/Advantage Pac) Feet inches fractions ( /thread-18499.html) |

(41CX w/Advantage Pac) Feet inches fractions - DMaier - 06-22-2022 09:35 PM
This code takes decimal inches, e.g., 14.25 in X and returns the following in Alpha: - 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:
Code:
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. RE: (41CX w/Advantage Pac) Feet inches fractions - Xorand - 06-27-2022 01:25 AM
What should be in register 00? The code starts out by recalling 00 and multiplying it by x, adding 0.5, then dividing by register 00. By default, my register 00 was equal to zero, so I immediately got a data error when dividing. RE: (41CX w/Advantage Pac) Feet inches fractions - Thomas Klemm - 06-27-2022 04:53 AM
(06-22-2022 09:35 PM)DMaier Wrote: The maximum denominator, which should be a power of 2, is assumed to be set in register 1. Note that the code rounds to the nearest fraction. Based on the code that should be register 00 instead. The sample output uses 8, but you could also use 16. RE: (41CX w/Advantage Pac) Feet inches fractions - Xorand - 06-27-2022 04:39 PM
Ah, ok, that makes more sense. Will give it another try. Edited to add: Yes, that worked. Thanks! RE: (41CX w/Advantage Pac) Feet inches fractions - Thomas Klemm - 06-27-2022 06:40 PM
Nice to see it's working for you now. (06-27-2022 01:25 AM)Xorand Wrote: The code starts out by recalling 00 and multiplying it by x, adding 0.5, then dividing by register 00. You missed taking the integral part with INT: Code: `RCL 00` This multiplies the number by the maximum denominator and rounds it to the nearest integer. It makes sure we end up with nice fractions. Later on the fraction is reduced if possible: Code: `RCL 00` We could use just .5 instead of 0.5 to save a precious byte and omit the redundant RTN statement at the END to save another one. RE: (41CX w/Advantage Pac) Feet inches fractions - Xorand - 06-27-2022 11:01 PM
(06-27-2022 06:40 PM)Thomas Klemm Wrote: Nice to see it's working for you now. I was paraphrasing, but yes, I saw that. True on the .5 and RTN. I've got it saved off to card now. |