HP Forums
Get "de-string" an expression - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Get "de-string" an expression (/thread-3321.html)



Get "de-string" an expression - Angus - 03-09-2015 01:11 PM

When given a String like "#AAh". How can that be changed to an integer constant #AAh?
I had in mind that CAS(String) is a way to convert a String to its (cas)meaning. Is that right? And why would that not work in the given example.
Please also look at the code:

Code:
EXPORT INT_HEX(X)
BEGIN
  CASE
    IF TYPE(X)==0 THEN R→B(X,32,4); END;
    IF TYPE(X)==1 THEN SETBASE(X,Base); END; //Base has already been set to 3
    IF TYPE(X)==2 THEN  CAS("#"+X+"h"); END; //input String like "AA" should return #AAh
    DEFAULT "";
   END;
 // R→B(X,32,4);
END;

edit: remembering Han's tutorial about cas programs I tried locally assigning str:="#"+X+"h"; CAS(str); which SEEMS to work better, but apparently always leads to everything but the desired result.... dec semms to be preferred.

Can someone help with the functionality I am looking for?


RE: Get "de-string" an expression - Angus - 03-09-2015 01:24 PM

Code:

EXPORT INT_HEX(X)
BEGIN
  LOCAL str;
  CASE
    IF TYPE(X)==0 THEN R→B(X,32,4); END;
    IF TYPE(X)==1 THEN SETBASE(X,Base); END; //Base is already set to 3
    IF TYPE(X)==2 THEN str:="#"+X+"h";  INT_HEX( CAS(str)); END; //input String like "AA" should return #AAh
    DEFAULT "";
   END;
 // R→B(X,32,4);
END;

That works. But I do not understand what CAS() is doing to integers.


RE: Get "de-string" an expression - DrD - 03-09-2015 01:56 PM

R→B(approx("#AAh")); // Who would have thought?


RE: Get "de-string" an expression - Angus - 03-09-2015 02:02 PM

Cool to see an other working solution! Thank you.
However is using approx() so obvious that I should sense cynicism in your comment? I am not sure.


RE: Get "de-string" an expression - DrD - 03-09-2015 02:17 PM

No cynicism intended, although I see your thinking on my poor phrasing! It's just that I tried various tools, while scanning through the catalog, and happened to land on "approx()." I never would have guessed that to be a viable solution! Damn good thing it wasn't Zapprox, or I would've been here until the next blue moon, whenever that is!

-Dale-


RE: Get "de-string" an expression - Angus - 03-09-2015 02:38 PM

How would you classify your solution? Is it intended or logical behaviour or is it just working out of luck? Or to put it in other words? How high of a risk do you see to be confronted with non working code after a future firmware update?
The cleanest solution is the best solution. What could it be.


RE: Get "de-string" an expression - cyrille de brébisson - 03-09-2015 05:11 PM

Hello,

is EXPR what you are looking for?

Cyrille


RE: Get "de-string" an expression - Angus - 03-10-2015 05:47 AM

Best solution I would say :-) Thank you