base conversion problems...
09-05-2017, 11:29 AM (This post was last modified: 09-05-2017 01:04 PM by Stevetuc.)
Post: #15
 Stevetuc Senior Member Posts: 313 Joined: Jan 2014
RE: base conversion problems...
(09-05-2017 08:26 AM)webmasterpdx Wrote:  I have a decent program for converting bases...

First, here are some utility functions I use, including the key definition.

Code:
 // BASE CONVERSION KEY KA_3() BEGIN RETURN STRING(EVAL(MBase())); END; // DEFINE MENU EXPORT PUTMENU(mTXT) BEGIN DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6)); END; // SETS mSEL GLOBAL VIA MENU SELECT EXPORT GETMENU(mx,my,mTXT) BEGIN LOCAL mSEL; mSEL:=0; IF my≥220 AND my≤239 THEN CASE  IF mx≥0 AND mx≤51 AND mTXT(1)>"" THEN   mSEL:=1;  END;  IF mx≥53 AND mx≤104 AND mTXT(2)>"" THEN   mSEL:=2;  END;  IF mx≥106 AND mx≤157 AND mTXT(3)>"" THEN   mSEL:=3;  END;  IF mx≥159 AND mx≤210 AND mTXT(4)>"" THEN   mSEL:=4;  END;  IF mx≥212 AND mx≤263 AND mTXT(5)>"" THEN   mSEL:=5;  END;  IF mx≥265 AND mx≤319 AND mTXT(6)>"" THEN   mSEL:=6;  END; END; // CASE END; // IF MENU RETURN mSEL; END; // BEGIN

And here is the base conversion program itself.

Code:
 EXPORT MBase() BEGIN LOCAL men,m,m1,mx,my,s; // initialize men:={"","BIN","OCT","DEC","HEX","EXIT"}; PUTMENU(men); REPEAT // WAIT FOR A MOUSE CLICK  m:=WAIT(−1); UNTIL (m(1)==3 OR m(1)==7); mx:=m(2); my:=m(3); s:=GETMENU(mx,my,men); IF (s==1  OR s==6) THEN RETURN END; RETURN s:=SETBASE(Ans(1),s-1); END; // BEGIN

Enjoy...

A couple of changes I made to my version allow the function MBase() to be also usable from the command line using passed parameter in both rpn and algebraic/textbook

In the base conversion program:

EXPORT MBase(in)
...
RETURN s:=SETBASE(in,s-1);

In the key definitions:
...
RETURN STRING(EVAL(MBase(Ans(1))));

It may be useful to some..
 « Next Oldest | Next Newest »

 Messages In This Thread base conversion problems... - webmasterpdx - 09-01-2017, 10:24 AM RE: base conversion problems... - webmasterpdx - 09-01-2017, 11:47 AM RE: base conversion problems... - Helge Gabert - 09-01-2017, 05:24 PM RE: base conversion problems... - webmasterpdx - 09-02-2017, 03:23 AM RE: base conversion problems... - Helge Gabert - 09-02-2017, 05:34 AM RE: base conversion problems... - Joe Horn - 09-02-2017, 05:58 AM RE: base conversion problems... - Eddie W. Shore - 09-04-2017, 07:41 PM RE: base conversion problems... - Stevetuc - 09-02-2017, 08:27 AM RE: base conversion problems... - webmasterpdx - 09-02-2017, 10:15 AM RE: base conversion problems... - Stevetuc - 09-02-2017, 08:35 PM RE: base conversion problems... - webmasterpdx - 09-03-2017, 02:07 AM RE: base conversion problems... - leprechaun - 09-05-2017, 07:05 AM RE: base conversion problems... - webmasterpdx - 09-05-2017, 08:26 AM RE: base conversion problems... - Stevetuc - 09-05-2017 11:29 AM RE: base conversion problems... - webmasterpdx - 09-05-2017, 08:52 AM RE: base conversion problems... - webmasterpdx - 09-05-2017, 11:09 PM

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