Get "de-string" an expression
03-09-2015, 01:11 PM (This post was last modified: 03-09-2015 01:22 PM by Angus.)
Post: #1
 Angus Member Posts: 212 Joined: Feb 2014
Get "de-string" an expression
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?
03-09-2015, 01:24 PM
Post: #2
 Angus Member Posts: 212 Joined: Feb 2014
RE: Get "de-string" an expression
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.
03-09-2015, 01:56 PM
Post: #3
 DrD Senior Member Posts: 1,101 Joined: Feb 2014
RE: Get "de-string" an expression
R→B(approx("#AAh")); // Who would have thought?
03-09-2015, 02:02 PM
Post: #4
 Angus Member Posts: 212 Joined: Feb 2014
RE: Get "de-string" an expression
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.
03-09-2015, 02:17 PM
Post: #5
 DrD Senior Member Posts: 1,101 Joined: Feb 2014
RE: Get "de-string" an expression
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-
03-09-2015, 02:38 PM (This post was last modified: 03-09-2015 02:38 PM by Angus.)
Post: #6
 Angus Member Posts: 212 Joined: Feb 2014
RE: Get "de-string" an expression
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.
03-09-2015, 05:11 PM
Post: #7
 cyrille de brébisson Senior Member Posts: 932 Joined: Dec 2013
RE: Get "de-string" an expression
Hello,

is EXPR what you are looking for?

Cyrille
03-10-2015, 05:47 AM
Post: #8
 Angus Member Posts: 212 Joined: Feb 2014
RE: Get "de-string" an expression
Best solution I would say :-) Thank you
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)