HP Forums

Full Version: Get "de-string" an expression
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.
R→B(approx("#AAh")); // Who would have thought?
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.
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-
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.
Hello,

is EXPR what you are looking for?

Cyrille
Best solution I would say :-) Thank you
Reference URL's