17bii unit conversions - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: 17bii unit conversions (/thread-215606.html) 17bii unit conversions - Dave Britten - 03-26-2012 Has anybody found any clever solver tricks for the 17bii that allow making unit converters that work like on the 19bii? By that I mean, store your input unit, then solve for any desired output unit. I'm sure there are plenty of L(), G(), and S() tricks I haven't fully explored yet. Re: 17bii unit conversions - Don Shepherd - 03-26-2012 Here's one from about six months ago. Re: 17bii unit conversions - M. Joury - 03-26-2012 Thanks Don! Re: 17bii unit conversions - Dave Britten - 03-26-2012 That looks pretty close to the technique I've used before, but it looks like it's limited to converting between mm and in, or m and ft, or km and mi. So there's no way to go from, say, in to km. I'd like to get as close to the 19bii unit converter as possible, so you could enter any one of mm, in, m, ft, km, or mi, and then solve for any one of the remaining five. I've got an idea that I think I'll tinker with on my 200LX, since that's a bit easier for typing out long formulas. Re: 17bii unit conversions - Don Shepherd - 03-26-2012 Dave, I think I see what you want. It may be possible, but you will have to check and see which value was entered so you can convert from that to what you want, and if you do a conversion after that there will be two values already present, so you'll have to figure out what to do in that situation (maybe that's OK, just convert from either of the two). I'll play with this tonight when I get home. Re: 17bii unit conversions - Dave Britten - 03-26-2012 This is what I tried so far (on my 200LX, so the syntax and formatting will be a tiny bit different). It doesn't seem to behave as desired, though. ```L(val:IF(S(mm):mm/10:0)+IF(S(m):m*100:0)+IF(S(cm):cm:0))=IF(i=1:cm:L(cm:val)*L(i:1)) ``` The idea would be to do Clear Data, store the value into the appropriate starting unit, then immediately solve for that unit. That will convert it to cm and store that value in cm. (The variable i is used to indicate if the solver has been initialized.) Then you would be able to pick any of the other units in the formula, and it will convert them from cm. I suspect something is going wrong with setting val on the left side, and stuffing it into cm on the right side. When I clear the solver, store a value into mm, and solve for mm, it just zeros out mm, cm, and val, and sets i to 1. If I remove '*L(i:1)' from the right side to prevent initializing i, it initializes cm properly, but then you can't solve for the other units. Re: 17bii unit conversions - Don Shepherd - 03-26-2012 Dave, this would be my approach. I only took it as far as 3 units: IN, FT, and MI, but it could be extended to include the other three units as well. You would have to Clear Data between calculations: ```IF(S(IN): IF(FT>0:FTx12:IF(MI>0:MIx63360:0))-IN :IF(S(FT): IF(IN>0:IN/12:IF(MI>0:MIx5280:0))-FT :IF(IN>0:IN/63360:IF(FT>0:FT/5280:0))-MI ) ) ``` Re: 17bii unit conversions - Dave Britten - 03-26-2012 This almost works, but it seems to behave unpredictably (at least on my 200LX): ```L(val:IF(S(mm):mm/10:0)+IF(S(m):m*100:0)+IF(S(cm):cm:0))=IF(i=0:L(i:val):i) ``` The idea is to load 'val' with whatever value is in the variable being solved for, and then if 'i' is zero (i.e. it's the first "run"), load 'val' into 'i'. Subsequent runs then use this value that was stored in 'i' (which in this case, would be the length normalized to cm). This actually seems to be working most of the time. But for some reason, if I do Clear Data, I can't reinitialize using the same variable/unit I just solved for. It'll just zero it out. The sequence looks something like this: ```18 [mm] "mm = 18" [mm] "mm = 18" ('i' gets set here) [cm] "cm = 1.8" [Clear Data] 15 [cm] "cm = 15" [cm] "cm = 0" ('i' stays at zero) ``` Not totally sure what's going on here. I'll have to try it on my 17bii and 19bii tonight. Re: 17bii unit conversions - Don Shepherd - 03-26-2012 Dave, I entered your equation on my 17bii and got these results: ```clear data 18 mm "mm = 18" mm "mm = 0" cm "cm = 0" ``` You are blazing new territory here. I have to admit I don't understand exactly what your equation is doing. I haven't tried it on my 19b but I expect the results would be the same. Re: 17bii unit conversions - Dave Britten - 03-26-2012 Yeah, just tried it on my 19bii and 17bii. Didn't work on either of them. The variables 'val' and 'i' never get set. Back to the drawing board. Re: 17bii unit conversions - Bill (Smithville, NJ) - 03-26-2012 Hi Dave & Don, This is a very interesting solve problem. Looks simple, but is a lot deeper than it looks. My first few tries were trying to enter FEET into FT and then press a second time, but no matter what I tried, the solver would always zero feet out. The work around was to use a dummy variable X. The following listing is from the CPACK200 program, but should work on a real HP-17BII. ```{IF (S(MILE): 0*FT+ 0*IN* 0*KM+ 0*M+ 0*X+ MILE-G(X)+ 0*L(FT:MILE*5280)+ 0* L( IN:FT* 12) + 0* L( KM:MILE*1.60934)+ 0*L(M:MILE*1609.34): IF (S(FT): FT-G(X)+ 0*L(MILE:FT/5280)+ 0*L(IN:FT*12)+ 0*L(KM:FT/3280.8)+ 0*L(M:FT/3.2808):0)) } ``` Takes two steps to do a conversion: To convert Miles to FT, IN, KM, and M, enter the miles into X and then press MILES key to do the conversion. Results are in each of the variables. Likewise for Inches, enter inches into X and then press IN key. The routine could be expanded to do the remaining units. Bill Re: 17bii unit conversions - Dave Britten - 03-27-2012 Hmm, interesting, if a bit "wordy". I'll have to play with that and see if there's a way to do it without entering the conversion factors twice. I have an idea, but it might be too crazy to work (like my last attempt). :) Re: 17bii unit conversions - Dave Britten - 03-27-2012 Alright, this works on my 19bii, but there are two problems with it. 1. It's kind of slow. 2. It's completely insane. I'll try to add some C-style inline comments, since it's not obvious what's going on here. ```//Throwaway values (all the L() magic happens in here). 0*( //Store the proper conversion factor in F, and temp CM value in V L(V: IF(S(MM):G(MM)*L(F:.1):0) +IF(S(M):G(M)*L(F:100):0) +IF(S(CM):G(CM)*L(F:1):0) ) //Put value from V into CM on first run +IF(G(CM)=0:L(CM:G(V)):0) ) //Choose the correct equation based on what variable to solve for. //Moving the -G(CM) outside the IF breaks it for some reason. +IF(S(M):M*G(F)-G(CM):0) +IF(S(CM):CM*G(F)-G(CM):0) +IF(S(MM):MM*G(F)-G(CM):0) ``` But it works! All you do is Clear Data, store your starting unit, then immediately solve for that same unit. You'll get the same value back. Then if you solve for any other variable, you'll get the amount converted to that unit.