Re: Help Squeezing some HP67/97 code Message #5 Posted by Valentin Albillo on 23 Nov 2005, 7:09 a.m., in response to message #1 by Howard Owen
Hi, Howard:
If you ever decide to port your YATZ program to the HP-71B, this does the trick:
VAL(STR$(N)[P,P])
where N is your number and P is the desired digit's position.
So, for instance, if N is 3141592654 you would have:
VAL(STR$(N)[1,1]) -> 3, the digit at the 1st position
VAL(STR$(N)[3,3]) -> 4, the digit at the 3rd position
and so on. Also, should you decide to port your game to the HP-15C, these steps will do:
STO RAN#
X<>Y
10^X
RCL RAN#
*
FRAC
10
*
INT
assuming the digit positions are counted this way, for example for 3141592654:
digit position 0 1 2 3 4 5 6 7 8 9
orig. number 3 1 4 1 5 9 2 6 5 4
so, with the desired position in Y and the orig. number in X, executing the above steps would do the following (say you want the digit at position 6):
T: T T: Z
Z: Z ------> Z: Z
Y: 6 Y: 3141592654
X: 3141592654 X: 2
so your original number is preserved intact in Y, the desired digit is of course in X, plus the original contents of Z are preserved as well.
If you want to count digit positions starting at 1 instead of 0, simply subtract 1 from Y after the X<>Y. The routine is quite fast as it uses no LOG instructions, just a single, integer-argument 10^X, and would be even shorter if the HP-15C had either the SIGN or the MOD (or RMD, remainder) functions built-in, which, alas, it doesn't ... nobody's perfect.
BTW, I have no HP-15C at hand right now, but believe the above steps are correct.
Best regards from V.
Edited: 23 Nov 2005, 7:11 a.m.
|