The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

17bii unit conversions
Message #1 Posted by Dave Britten on 26 Mar 2012, 7:20 a.m.

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
Message #2 Posted by Don Shepherd on 26 Mar 2012, 8:03 a.m.,
in response to message #1 by Dave Britten

Here's one from about six months ago.

            
Re: 17bii unit conversions
Message #3 Posted by M. Joury on 26 Mar 2012, 8:16 a.m.,
in response to message #2 by Don Shepherd

Thanks Don!

            
Re: 17bii unit conversions
Message #4 Posted by Dave Britten on 26 Mar 2012, 8:57 a.m.,
in response to message #2 by Don Shepherd

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
Message #5 Posted by Don Shepherd on 26 Mar 2012, 10:46 a.m.,
in response to message #4 by Dave Britten

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
Message #6 Posted by Dave Britten on 26 Mar 2012, 11:26 a.m.,
in response to message #5 by Don Shepherd

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
Message #7 Posted by Don Shepherd on 26 Mar 2012, 1:36 p.m.,
in response to message #6 by Dave Britten

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
Message #8 Posted by Dave Britten on 26 Mar 2012, 4:07 p.m.,
in response to message #7 by Don Shepherd

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
Message #9 Posted by Don Shepherd on 26 Mar 2012, 4:53 p.m.,
in response to message #8 by Dave Britten

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
Message #10 Posted by Dave Britten on 26 Mar 2012, 5:15 p.m.,
in response to message #9 by Don Shepherd

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
Message #11 Posted by Bill (Smithville, NJ) on 26 Mar 2012, 7:17 p.m.,
in response to message #1 by Dave Britten

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
Message #12 Posted by Dave Britten on 27 Mar 2012, 7:55 a.m.,
in response to message #11 by Bill (Smithville, NJ)

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
Message #13 Posted by Dave Britten on 27 Mar 2012, 11:59 a.m.,
in response to message #12 by Dave Britten

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.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall