11-22-2005, 12:20 PM
I'm trying to shoehorn YATZ into the HP67/97 I'm doing fine with labels, but I'm running out of program lines. The exercise has convinced me that I can finish the port to the 33S, however, so I've shelved the 97 version for now and am working on the 33S. I'm looking for opportunities to shrink the code size while I do that, however. Below is an algorithm I developed for extracting the nth digit (counting left to right) in a number. It is rather lengthy. Can anyone see a way to shrink it? Is there another approach to this problem anyone is aware of that might be shorter?
L0001 *LBL L ! Extract the Yth digit (counting left to right) from the number in X
L0002 ENTER ! Copy the number
L0003 LOG ! Desired order is the opposite of the exponent view of the number
L0004 IP ! So calculate a complement we can subtract from the input digit position
L0005 2 ! to yield the power of ten digit position plus one. This will scale the
L0006 + ! number so the desired digit will be in the -1 power of ten position
L0007 x<>y ! Fiddle the stack for the next calculation
L0008 RDN !
L0009 x<>y ! OK, we have input digit position in X and the complement in Y
L0010 - ! Difference is as stated above
L0011 x<>y !
L0012 RDN ! Number is in Y and Scaling power in X
L0013 10^x ! Divisor to bring digit down to first place to right of the decimal
L0014 / ! Divide it
L0015 FP ! Throw away higher (lower) digits.
L0016 10 ! Scale the desired digit back up
L0017 * !
L0018 IP ! Digit is now isolated
L0019 RTN
Regards,
Howard
Edited: 22 Nov 2005, 1:00 p.m.